// interpolacja_newtona_11k2.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include using namespace std; double f(double x); double W(double x1, double x2, double x3, double x, double a0, double a1, double a2, double a3); int _tmain(int argc, _TCHAR* argv[]) { double x1, x2, x3, dx, er, ermax, erdop, xStart, xEnd, xp, a0, a1, a2, a3; int m = 3; // przedzialy double d[5][5]; double x[5]; xStart = 0.0; xEnd = 2.0*asin(1.0); cout << endl << "Podaj blad="; cin >> erdop; do { ermax = 0.0; xStart = 0.0; xEnd = 2.0*asin(1.0); dx = (xEnd - xStart) / m; x[1] = xStart; x[4] = xEnd / m; x[2] = x[1] + (x[4] - x[1]) / 3; x[3] = x[1] + (x[4] - x[1]) * 2 / 3; xp = x[1] + dx / 2.0; for (int i = 0; iermax) ermax = er; x[1] = x[4]; x[4] = x[1] + dx; x[2] = x[1] + (x[4] - x[1]) / 3; x[3] = x[1] + (x[4] - x[1]) * 2 / 3; xp = x[1] + dx / 2.0; } m++; } while (ermax>erdop); printf("\nliczba przedzialow=%d blad=%f", m - 1, ermax); cout << endl; system("pause"); return 0; } double f(double x) { return sin(x); } //--------------------------------------- double W(double x1, double x2, double x3, double x, double a0, double a1, double a2, double a3) { return a0+ a1*(x - x1) + a2*(x - x1)*(x - x2) + a3*(x - x1)*(x - x2)*(x - x3); }