Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double f1(double c)
- {
- return(c-(c*c-5)/(2*c)); //f1(x) = x - f(x)/f'(x)
- }
- int main()
- {
- int j=0;
- double a,b,E,x,z;
- cout<<" !<Course work. Teacher: Pijov Y.V.>! "<<endl<<endl;
- cout<<" !<Author: Yefimov D.R. @ OCCTOEU 2012>! "<<endl<<endl;
- cout<<" <NOTE: program for solving an equation by simple iterations.> "<<endl<<endl;
- while(j!=2)
- {
- int n=0;
- cout<<"<Info>: The root must be on the interval between -A- and -B-"<<endl;
- cout<<"<Step #1>: ENTER the value -A- (for example: 2): ";
- cin>>a;
- cout<<"<Step #2>: ENTER the value -B- (for example: 3): ";
- cin>>b;
- cout<<"<Step #3>: ENTER the value -EPSILON- (for example: 0.01): ";
- cin>>E;
- x=(a+b)/2;
- do
- {
- cout<<"Step "<<n+1<<": "<<x<<endl; //âûâîä çíà÷åíèé íà èòåðàöèÿõ, åñëè íóæíî
- z=x;
- x=f1(x);
- n++;
- }
- while ((fabs(x-z))>=E);
- cout<<endl;
- cout<<" !CALCULATION PROCESS IS -COMPLETED-! "<<endl<<endl;
- cout<<" <Results>: "<<endl;
- cout<<"Value -X- equals: "<<x<<endl;
- cout<<"Number of -STEPS- equals: "<<n<<endl<<endl;
- cout<<"Continue or not? (1 - YES; 2 - NO): ";
- cin>>j;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement