Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. ALG 1 METODA NEWTON PT F(X)=0
  2.  
  3. #include <iostream>
  4. #include <math.h>
  5. #include <conio.h>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. #define ITMAX 100
  11. double error = 0.0001;
  12.  
  13. double f1(double x) {
  14. return x * exp(x) - 1;
  15. }
  16.  
  17. double f2(double x) {
  18. return exp(x) + x * exp(x);
  19. }
  20.  
  21. int main() {
  22.  
  23. int n = 1;
  24. double x = 0;
  25.  
  26. while (fabs(f1(x)) > error && n <= ITMAX) {
  27. x = x - ( f1(x) / f2(x) );
  28. n = n + 1;
  29. }
  30.  
  31. if (n > ITMAX) {
  32. cout << "In " << n << " iterati nu a fost realizata aproximarea dorita." << endl;
  33. } else {
  34. cout << "Aproximarea dorita este: " << x << endl;
  35. }
  36.  
  37. _getch();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement