Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. double f(double x)
  9. {
  10. return x*exp(x)- pow(x,2);
  11. }
  12. double Fpr(double x)
  13. {
  14. return exp(x)*(x+1)-(2*x);
  15. }
  16. double blad(double alfa, double x)
  17. {
  18. return fabs(alfa-x);
  19. }
  20. int main()
  21. {
  22. int k=0;
  23. double x;
  24. double eps;
  25. double u;
  26. double alfa = 0.0;
  27. cout.precision(16);
  28. cout<<"podaj punkt"<<endl;
  29. cin>>x;
  30. cout<<"podaj eps"<<endl;
  31. cin>>eps;
  32. eps = pow(10,-eps);
  33. do
  34. {
  35. cout << "wartosc f(x): " << f(x) <<"\tDla x: " << x<<endl;
  36. u = ( f(x) ) / Fpr(x) ;
  37. x= x - (u/(2*Fpr(x)))*((3*Fpr(x))-(Fpr(x-u)));
  38. k++;
  39.  
  40. }
  41. while(fabs(u)>=eps);
  42.  
  43.  
  44. //system("cls"); //podgladanie krokow wlaczone, mozna tym wylaczyc
  45.  
  46.  
  47. cout <<"liczba krokow = "<<k<<endl<<endl;
  48. cout << "f(x): "<< f(x)<<endl;
  49. cout <<"x : "<<x<<endl;
  50. cout<< "Blad bezwzgledny to "<< blad(alfa,x) <<endl;
  51. _getch();
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement