Showing posts with label NM. Show all posts
Showing posts with label NM. Show all posts

Thursday, September 24, 2015

Write an Algorithm for the Secant Method.

Step1:- Decide two initial points x1 & x2, & accuracy level required, E.
Step2:- Compute f ( x1 ) & f ( x2 )
Step3:- Compute
             x3 = x2 - ( (f 2 (x2-x1) ) / ( f 2 - f 1 ) )
Step4:- Test for accuracy of x3.
             If absolute value of (x3 – x2) / x3 > E, then
                  Set x1 = x2 & f1 = f2
                  Set x2 = x3 & f2 = f (x3)
                  Go to step 3
            otherwise,
                  set root = x3
            print results.
Step5:- Stop



Write an Algorithm for the Newton - Raphson Method.

Step1:-  Assign an initial value to x, say x0 & set value of E.
Step2:-  Evaluate f ( x0 ) & f ' ( x0 ) .
Step3:-  Find the improved estimate to x0.
              x1 = x0 - ( f (x0) / f ' (x0) )
Step4:-  Check for accuracy of the latest estimate.
              Compare relative error to a predefined value E.
              If absolute value of (x1 - x0) / x1 ≤  E
                   Stop.
              else
                  Continue.
Step5:-  Replace x0 by x1 & repeat Step 3 & Step 4.



Write an Algorithm for the Bisection Method.

Step1:-  Decide initial values for x1 & x2 & stopping criteria, E.
Step2:-  Compute f1 = f ( x1 ) & f2 = f ( x2 ).
Step3:-  If ( f1 * f2) > 0,  x1 & x2 do not bracket any root & go to step 7.
             Otherwise continue.
Step4:-  Compute x0 = ( x2 - x1 ) / x2 & compute f0 = f ( x0 ).
Step5:-  If ( f1 = f0 ) < 0 then
                    Set x2 = x0
              else
                    Set x1 = x0
                    Set f1 = f0
 Step6:-  If absolute value of ( x2 - x1 ) /  x2 is less than error E, then
                    root = ( x2 - x1 ) / 2
                    write the value of root
                    go to step 7.
              else
                    go to step 4.
Step7:-  Stop.