Advertisement
Guest User

Work

a guest
Aug 29th, 2012
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <iostream>
  2.     #include <math.h>
  3.     using namespace std;
  4.      
  5.     double f1(double c)
  6.     {
  7.          return(c-(c*c-5)/(2*c)); //f1(x) = x - f(x)/f'(x)
  8.     }
  9.      
  10.     int main()
  11.     {
  12.          int j=0;
  13.          double a,b,E,x,z;
  14.          cout<<"                    !<Course work. Teacher: Pijov Y.V.>! "<<endl<<endl;
  15.          cout<<"                  !<Author: Yefimov D.R. @ OCCTOEU 2012>! "<<endl<<endl;
  16.          cout<<"            <NOTE: program for solving an equation by simple iterations.> "<<endl<<endl;
  17.          while(j!=2)
  18.          {
  19.              
  20.              int n=0;
  21.              cout<<"<Info>: The root must be on the interval between -A- and -B-"<<endl;
  22.              cout<<"<Step #1>: ENTER the value -A- (for example: 2): ";
  23.              cin>>a;
  24.              cout<<"<Step #2>: ENTER the value -B- (for example: 3): ";
  25.              cin>>b;
  26.              cout<<"<Step #3>: ENTER the value -EPSILON- (for example: 0.01): ";
  27.              cin>>E;
  28.      
  29.              x=(a+b)/2;    
  30.              do
  31.              {
  32.                  cout<<"Step "<<n+1<<": "<<x<<endl; //âûâîä çíà÷åíèé íà èòåðàöèÿõ, åñëè íóæíî                            
  33.                  z=x;
  34.                  x=f1(x);
  35.                  n++;
  36.      
  37.              }
  38.              while ((fabs(x-z))>=E);
  39.          
  40.              cout<<endl;
  41.              cout<<"                    !CALCULATION PROCESS IS -COMPLETED-! "<<endl<<endl;
  42.              cout<<"      <Results>: "<<endl;
  43.              cout<<"Value -X- equals: "<<x<<endl;
  44.              cout<<"Number of -STEPS- equals: "<<n<<endl<<endl;
  45.              cout<<"Continue or not? (1 - YES; 2 - NO): ";
  46.              cin>>j;
  47.       }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement