SHARE
TWEET

Untitled

a guest Oct 10th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <iostream>
  4.  
  5. #define EPSILON 0.01
  6.  
  7. using namespace std;
  8.  
  9. float getFuncResult(float x) {
  10.     return (0.5 * pow(x, 2) - sin(x));
  11. }
  12.  
  13. float getDerivative(float x) {
  14.     return (x - cos(x));
  15. }
  16.  
  17. void main() {
  18.     float x0 = 0.5;
  19.     float xnext;
  20.  
  21.     for (;;) {
  22.         xnext = x0 - getFuncResult(x0) / getDerivative(x0);
  23.         if (abs(xnext - x0) < EPSILON) break;
  24.         x0 = xnext;
  25.     }
  26.     cout << "Result: " << x0 << endl;
  27.     system("pause");
  28. }
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