Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement