#include #include #include using namespace std; /* Calcul de la derivee d'une fonction */ double f(double x){ return atan(x); } double f2(double x){ return x*(x-1)*(x-2); } double derivee(double (*g)(double), double x0, double Dx){ double res; res = (*g)(x0-2.*Dx) - 8.*(*g)(x0-Dx) + 8.*(*g)(x0+Dx) - (*g)(x0+2.*Dx); return res/(12.*Dx); } int main(){ double x0 = 2.; double Dx = 2.; int i; cout << setprecision(15); cout << "Arctan'(" << x0 << ")" << endl; for (i = 0; i < 10; i++){ cout << Dx << " : " << derivee(f,x0,Dx) << endl; Dx = Dx/2.; } cout << "Exact : " << 1./(1.+x0*x0) << endl << endl; Dx = 2.; cout << "[x(x-2)(x-1)]'(" << x0 << ")" << endl; for (i = 0; i < 10; i++){ cout << Dx << " : " << derivee(f2,x0,Dx) << endl; Dx = Dx/2.; } cout << "Exact : " << 3.*x0*x0-6.*x0+2. << endl; return 0; }