// Example of for loops to compute a derivative. // derive.cpp // ESC 104 #include #include main() { double x; double f_of_x; double f_of_xh; double derivative; int i; double h = 0.00001; cout << setprecision(4) << setiosflags( ios::fixed | ios::showpoint ); for( i=0; i<20; i++) { x = (double)i; f_of_x = 2*x*x + 3*x + 4; x += h; f_of_xh = 2*x*x + 3*x + 4; derivative = (f_of_xh - f_of_x )/h; cout << "Derivative at x = " << (x-h) << " is " << derivative << endl; } return 0; }