SHARE
TWEET

Untitled

a guest May 21st, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. double f(double x){
  8.     return sin(pow(x,2))-6*x+1;
  9. }
  10.  
  11. double df(double x){
  12.     return 2 * cos(pow(x, 2)) - 6;
  13. }
  14.  
  15. int main()
  16.  
  17. {
  18.     const double eps = pow(10, -6);
  19.     int k = 0;
  20.     double x = 0.5;
  21.     double y = f(x);
  22.     double dy = df(x);
  23.     double xn = x - y / dy;
  24.     while (abs(xn - x) > eps){
  25.  
  26.         k++;
  27.         x = xn;
  28.         y = f(x);
  29.         dy = df(x);
  30.         xn = x - y / dy;
  31.     }
  32.  
  33.     cout << xn << endl <<  k << endl;
  34.  
  35.     return 0;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top