Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <cmath>
- #include <iomanip>
- #include <vector>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #define _CRT_SECURE_NO_WARNINGS
- using namespace std;
- int m;
- double ** getData(int a, int b, int m)
- {
- double **f = new double*[2];
- f[0] = new double[m];
- f[1] = new double[m];
- /*apr = new double[u];
- pog = new double[u];
- double e = 0;*/
- // x[i] = a + (i - 1) * (b - a) / (m - 1)
- // i = 1, m
- // f(x[j]0, phi 9x[j],c)
- // d(xj) f (xj) (xj,c)
- for (int i = 1; i <= m; i++)
- {
- f[0][i - 1] = a + (double)(i - 1) * (b - a) / (m - 1); //x[i]
- f[1][i - 1] = (double)4 * f[0][i - 1] - (double)7 * sin(f[0][i - 1]); //y[i]
- printf("%5.3lf - %7.3lf\n", f[0][i - 1], f[1][i - 1]);
- }
- return f;
- for (int j = 0; j <21; j++)
- {
- long double **g;
- g = new long double*[2];
- g[1] = new long double[21];
- g[2] = new long double[21];
- g[1][j] = a + j*(b - a) / 20;
- g[2][j] = pow(f[1][j], 2.0);
- /*for (int i = 0; i <=2; ++i)
- {
- g[2][j] = f[1];
- }*/
- }
- }
- // Вычисление коэффициентов аппроксимирующей прямой
- void getApprox(double **x, double *a, double *b, int n)
- {
- double sumx = 0;
- double sumy = 0;
- double sumx2 = 0;
- double sumxy = 0;
- for (int i = 0; i<n; i++) {
- sumx += x[0][i];
- sumy += x[1][i];
- sumx2 += x[0][i] * x[0][i];
- sumxy += x[0][i] * x[1][i];
- }
- *a = (n*sumxy - (sumx*sumy)) / (n*sumx2 - sumx*sumx);
- *b = (sumy - *a*sumx) / n;
- return;
- }
- int main()
- {
- double **x, a, b;
- int A, B, M, N;
- double **f;
- f = new double *[2];
- f[0] = new double[11];
- f[1] = new double[11];
- int j;
- system("chcp 1251");
- system("cls");
- printf("Input A: ");
- scanf_s("%d", &A);
- printf("Input B: ");
- scanf_s("%d", &B);
- printf("Input M: ");
- scanf_s("%d", &M);
- printf("Input N: ");
- scanf_s("%d", &N);
- x = getData(A, B, M);
- std::cout << "\n\n\tf(x)" << "\t\tapr(x)" << "\tpog" << std::endl;
- /*bila здесь ошибка в цикле*/
- for (int i = 0; i <21; i++)
- {
- double **g;
- g = new double*[2];
- g[1] = new double[21];
- g[2] = new double[21];
- double *apr, *pog;
- apr = new double[21];
- pog = new double[21];
- double e = 0;
- for (int j = 0; j < 11; j++)
- /*double **f;
- double *f = new double *[2];
- f[0] = new double[m];
- f[1] = new double[m];
- int j;*/
- if ((g[2][i] >= f[0][j]) && (g[2][i] <= f[0][j + 1]))
- {
- apr[i] = f[1][j] + (g[1][i] - f[0][j])*(f[1][j + 1] - f[1][j]) / (f[0][j + 1] - f[0][j]);
- pog[i] = g[2][i] - apr[i];
- }
- if ((i >= 14 && i <= 17) || (i >= 19 && i <= 20))
- std::cout << "\n" << i + 1 << ":" << setw(15) << g[2][i] << setw(15) << apr[i] << setw(15) << pog[i];
- else
- std::cout << "\n" << i + 1 << ":" << setw(15) << g[2][i] << setw(15) << apr[i] << setw(15) << pog[i];
- std::cout << "\n";
- system("pause");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment