Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- double f(double x){
- return sin(pow(x,2))-6*x+1;
- }
- double df(double x){
- return 2 * cos(pow(x, 2)) - 6;
- }
- int main()
- {
- const double eps = pow(10, -6);
- int k = 0;
- double x = 0.5;
- double y = f(x);
- double dy = df(x);
- double xn = x - y / dy;
- while (abs(xn - x) > eps){
- k++;
- x = xn;
- y = f(x);
- dy = df(x);
- xn = x - y / dy;
- }
- cout << xn << endl << k << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement