Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- inline double f(double x) { return log(x+1)-2*x*x+1; /* f(x) */ }
- inline double df(double x) { return 1/fabs(x+1)-4*x; /* f'(x) */ }
- int main() {
- // left
- int count = 0;
- double x = 2.0, dx = 1.0;
- for (int i = 0; i < 20; ++i, dx *= 0.1) {
- double dy = (f(x) - f(x-dx)) / dx;
- cout << i << ":\t";
- cout << "dx = " << setw(9) << dx << "\t";
- cout << "y'(x0) = " << dy << endl;
- }
- printf("check: %0.9f\n", df(2.0));
- return 0;
- }
Add Comment
Please, Sign In to add comment