Advertisement
Guest User

EX 2 Calcul Numeric

a guest
Feb 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include<math.h>
  3. #define ITMAX 100
  4.  
  5. using namespace std;
  6.  
  7. double error = 0.0001;
  8. double f1(double x)
  9. {
  10. return x * exp(x)-1;
  11. }
  12. double f2(double x)
  13. {
  14. return exp(x) + x * exp(x);
  15. }
  16. double modul(double a)
  17. {
  18. if(a < 0)
  19. {
  20. a *= -1;
  21. }
  22. return a;
  23. }
  24. double a = 2;
  25. int p = 2;
  26.  
  27. int main()
  28. {
  29. int n = 1;
  30. double x = 2;
  31. /*EX 1
  32. while(modul(f1(x)) > error && n <= ITMAX)
  33. {
  34. Ex 1
  35. x = x-(f1(x)/f2(x));
  36. n = n+1;
  37. }
  38. */
  39.  
  40. /*EX 2 */
  41. while(fabs(pow(x, p) - a) > error && n <= ITMAX)
  42. {
  43. //x = (1.0/p * ((p-1) * x + (a/pow(x, p-1))));
  44. x = ((p-1) * x + (a/pow(x, p-1)))/p;
  45. n = n+1;
  46. }
  47. if(n > ITMAX)
  48. {
  49. cout<<endl<<"In "<<n<<" iteratii nu a fost realizata aproximarea dorita";
  50. }
  51. else
  52. {
  53. cout<<endl<<"Aproximarea dorita este "<<x;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement