Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <stdlib.h>
- #include <conio.h>
- using namespace std;
- double f(double x)
- {
- return x*exp(x)- pow(x,2);
- }
- double Fpr(double x)
- {
- return exp(x)*(x+1)-(2*x);
- }
- double blad(double alfa, double x)
- {
- return fabs(alfa-x);
- }
- int main()
- {
- int k=0;
- double x;
- double eps;
- double u;
- double alfa = 0.0;
- cout.precision(16);
- cout<<"podaj punkt"<<endl;
- cin>>x;
- cout<<"podaj eps"<<endl;
- cin>>eps;
- eps = pow(10,-eps);
- do
- {
- cout << "wartosc f(x): " << f(x) <<"\tDla x: " << x<<endl;
- u = ( f(x) ) / Fpr(x) ;
- x= x - (u/(2*Fpr(x)))*((3*Fpr(x))-(Fpr(x-u)));
- k++;
- }
- while(fabs(u)>=eps);
- //system("cls"); //podgladanie krokow wlaczone, mozna tym wylaczyc
- cout <<"liczba krokow = "<<k<<endl<<endl;
- cout << "f(x): "<< f(x)<<endl;
- cout <<"x : "<<x<<endl;
- cout<< "Blad bezwzgledny to "<< blad(alfa,x) <<endl;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement