lecture 44 numerical analysis. solution of non-linear equations

46
Lecture 44 Numerica l Analysis

Upload: makayla-lane

Post on 26-Mar-2015

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Lecture 44Lecture 44

NumericalAnalysis

NumericalAnalysis

Page 2: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Solution of Solution of

Non-Linear Non-Linear EquationsEquations

Page 3: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Bisection MethodBisection MethodRegula-Falsi MethodRegula-Falsi MethodMethod of iterationMethod of iterationNewton - Raphson MethodNewton - Raphson MethodMuller’s MethodMuller’s MethodGraeffe’s Root Squaring Graeffe’s Root Squaring MethodMethod

Bisection MethodBisection MethodRegula-Falsi MethodRegula-Falsi MethodMethod of iterationMethod of iterationNewton - Raphson MethodNewton - Raphson MethodMuller’s MethodMuller’s MethodGraeffe’s Root Squaring Graeffe’s Root Squaring MethodMethod

Page 4: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Newton -Raphson Method

Newton -Raphson Method

Page 5: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

An approximation to An approximation to the root is given bythe root is given by

01 0

0

( )

( )

f xx x

f x

Page 6: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Better and successive Better and successive approximations approximations xx22, , xx33, …, , …, xxnn

to the root are obtained from to the root are obtained from

1

( )

( )n

n nn

f xx x

f x

N-R Formula

Page 7: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Newton’s algorithmNewton’s algorithm

To find a solution to To find a solution to f(x)=0f(x)=0 given an initial given an initial approximation approximation pp00

Page 8: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

INPUTINPUT initial approximation initial approximation pp00; tolerance TOL; maximum ; tolerance TOL; maximum

number of iterations Nnumber of iterations N00

OUTPUTOUTPUT approximate approximate solution p or message of failuresolution p or message of failure

Page 9: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Step 1Step 1Set Set I = 1I = 1

Step 2Step 2While i While i << N0 do Steps 3-6 N0 do Steps 3-6

Page 10: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Step 3Step 3 SetSet p = pp = p0 0 – f ( p– f ( p0 0 ) / f’ ( p) / f’ ( p0 0 ))

(compute p(compute pi i ).).

Step 4Step 4 If Abs (p – pIf Abs (p – p00) < TOL) < TOL

OUTPUTOUTPUT ( p ); ( p );(The procedure was successful.)(The procedure was successful.)

STOPSTOP

Page 11: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Step 5Step 5 SetSet i = i + 1i = i + 1

Step 6Step 6 Set pSet p00 = p = p (Update p(Update p0 0 ))

Step 7 Step 7 OUTPUTOUTPUT (The method failed after N(The method failed after N00 iterations, N iterations, N00

= ‘,N= ‘,N00 ) )

The procedure was unsuccessfulThe procedure was unsuccessful

STOPSTOP

Page 12: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

ExampleExampleUsing Maple to solve a Using Maple to solve a non-linear equation.non-linear equation.

cos( ) 0x x

Page 13: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Solution Solution The Maple command will be as The Maple command will be as follows,follows,Fsolve ( cos (x) -x);Fsolve ( cos (x) -x);

Page 14: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

alg023(); alg023(); This is Newton's MethodThis is Newton's MethodInput the function F(x) in terms of xInput the function F(x) in terms of xFor example:For example:> cos(x)-x> cos(x)-xInput initial approximationInput initial approximation> 0.7853981635> 0.7853981635Input toleranceInput tolerance> 0.00005> 0.00005

Page 15: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Input maximum number of Input maximum number of iterations - no decimal pointiterations - no decimal point> 25> 25Select output destinationSelect output destination1. Screen1. Screen2. Text file2. Text fileEnter 1 or 2Enter 1 or 2> 1> 1

Page 16: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Select amount of outputSelect amount of output1. Answer only1. Answer only2. All intermediate 2. All intermediate approximationsapproximationsEnter 1 or 2Enter 1 or 2> 2> 2

Page 17: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Newton's MethodNewton's Method I P F(P)I P F(P)

1 0.739536134 1 0.739536134 -7.5487470e-04-7.5487470e-04

2 0.739085178 2 0.739085178 -7.5100000e-08-7.5100000e-08

3 0.7390851333 0.739085133 0.0000000e-01 0.0000000e-01

Approximate solution = 0.73908513Approximate solution = 0.73908513

with F(P) = 0.0000000000with F(P) = 0.0000000000

Number of iterations = 3Number of iterations = 3

Tolerance = 5.0000000000e-05Tolerance = 5.0000000000e-05

Page 18: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Another ExampleAnother Example> > alg023(); alg023(); Input the function F(x) in Input the function F(x) in terms of x , terms of x , > sin(x)-1> sin(x)-1Input initial approximationInput initial approximation> 0.17853> 0.17853Input toleranceInput tolerance> 0.00005> 0.00005

Page 19: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Input maximum number of Input maximum number of iterations – no decimal pointiterations – no decimal point> 25> 25Select output destinationSelect output destination1. Screen1. Screen2. Text file2. Text fileEnter 1 or 2Enter 1 or 2>2>2

Page 20: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Select amount of outputSelect amount of output1. Answer only1. Answer only2. All intermediate 2. All intermediate approximationsapproximationsEnter 1 or 2Enter 1 or 2> 2> 2

Page 21: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Newton's MethodNewton's Method I P F(P)I P F(P) 1 1.01422964e+00 -1.5092616e-011 1.01422964e+00 -1.5092616e-01 2 1.29992628e+00 -3.6461537e-022 1.29992628e+00 -3.6461537e-02 3 1.43619550e+00 -9.0450225e-033 1.43619550e+00 -9.0450225e-03 4 1.50359771e+00 -2.2569777e-034 1.50359771e+00 -2.2569777e-03 5 1.53720967e+00 -5.6397880e-045 1.53720967e+00 -5.6397880e-04 6 1.55400458e+00 -1.4097820e-046 1.55400458e+00 -1.4097820e-04 7 1.56240065e+00 -3.5243500e-057 1.56240065e+00 -3.5243500e-05

More…More…

Page 22: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

8 1.56659852e+00 -8.8108000e-068 1.56659852e+00 -8.8108000e-06 9 1.56869743e+00 -2.2027000e-069 1.56869743e+00 -2.2027000e-06 10 1.56974688e+00 -5.5070000e-0710 1.56974688e+00 -5.5070000e-07 11 1.57027163e+00 -1.3770000e-0711 1.57027163e+00 -1.3770000e-07 12 1.57053407e+00 -3.4400000e-0812 1.57053407e+00 -3.4400000e-08 13 1.57066524e+00 -8.6000000e-0913 1.57066524e+00 -8.6000000e-09 14 1.57073085e+00 -2.1000000e-0914 1.57073085e+00 -2.1000000e-09 15 1.57076292e+00 -6.0000000e-1015 1.57076292e+00 -6.0000000e-10

Page 23: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Approximate solution Approximate solution = 1.57076292= 1.57076292with with F(P) =6.0000000000e-10F(P) =6.0000000000e-10Number of iterations = 15Number of iterations = 15Tolerance = Tolerance = 5.0000000000e-055.0000000000e-05

Page 24: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Bisection MethodBisection Method

> alg021();> alg021();This is the Bisection Method.This is the Bisection Method.Input the function F(x) in Input the function F(x) in terms of xterms of xFor example:For example:> x^3+4*x^2-10> x^3+4*x^2-10

Page 25: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Input endpoints A < B Input endpoints A < B separated by blankseparated by blank> 1 2> 1 2Input toleranceInput tolerance> 0.0005> 0.0005Input maximum number of Input maximum number of iterations - no decimal pointiterations - no decimal point> 25> 25

Page 26: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Select output destinationSelect output destination1.1.Screen , Screen , 2. Text file2. Text fileEnter 1 or 2Enter 1 or 2> 1> 1Select amount of outputSelect amount of output1. Answer only1. Answer only2. All intermediate approximations2. All intermediate approximationsEnter 1 or 2Enter 1 or 2> 2> 2

Page 27: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Bisection MethodBisection Method I P F(P)I P F(P) 1 1.50000000e+00 2.3750000e+00 1 1.50000000e+00 2.3750000e+00 2 1.25000000e+00 -1.7968750e+00 2 1.25000000e+00 -1.7968750e+00 3 1.37500000e+00 1.6210938e-013 1.37500000e+00 1.6210938e-01

Page 28: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

4 1.31250000e+00 -8.4838867e-01 4 1.31250000e+00 -8.4838867e-01 5 1.34375000e+00 -3.5098267e-01 5 1.34375000e+00 -3.5098267e-01 6 1.35937500e+00 -9.6408842e-02 6 1.35937500e+00 -9.6408842e-02 7 1.36718750e+00 3.2355780e-02 7 1.36718750e+00 3.2355780e-02 8 1.36328125e+00 -3.2149969e-02 8 1.36328125e+00 -3.2149969e-02 9 1.36523438e+00 7.2030000e-05 9 1.36523438e+00 7.2030000e-05 10 1.36425781e+00 -1.6046697e-02 10 1.36425781e+00 -1.6046697e-02 11 1.36474609e+00 -7.9892590e-03 11 1.36474609e+00 -7.9892590e-03

Approximate solution P = 1.36474609 Approximate solution P = 1.36474609 with F(P) = -.00798926with F(P) = -.00798926Number of iterations = 11 Number of iterations = 11 Tolerance = 5.00000000e-04Tolerance = 5.00000000e-04

Page 29: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

alg021(); Another example of the alg021(); Another example of the Bisection Method.Bisection Method.Input the function F(x) in terms Input the function F(x) in terms of x,of x,> cos(x)> cos(x)Input endpoints A < B separated Input endpoints A < B separated by blankby blank> 1 2> 1 2Input toleranceInput tolerance> 0.0005 > 0.0005

Page 30: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Input maximum number of iterations - Input maximum number of iterations - no decimal pointno decimal point> 25> 25Select output destinationSelect output destination1. Screen , 2. Text file1. Screen , 2. Text fileEnter 1 or 2Enter 1 or 2> 1> 1Select amount of outputSelect amount of output1. Answer only1. Answer only2. All intermediate approximations2. All intermediate approximationsEnter 1 or 2Enter 1 or 2> 2> 2

Page 31: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Bisection MethodBisection Method 1 P F(P)1 P F(P) 1 1.50000000e+00 7.0737202e-02 1 1.50000000e+00 7.0737202e-02 2 1.75000000e+00 -1.7824606e-01 2 1.75000000e+00 -1.7824606e-01 3 1.62500000e+00 -5.4177135e-02 3 1.62500000e+00 -5.4177135e-02 4 1.56250000e+00 8.2962316e-03 4 1.56250000e+00 8.2962316e-03 5 1.59375000e+00 -2.2951658e-02 5 1.59375000e+00 -2.2951658e-02

Page 32: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

6 1.57812500e+00 -7.3286076e-03 6 1.57812500e+00 -7.3286076e-03 7 1.57031250e+00 4.8382678e-04 7 1.57031250e+00 4.8382678e-04 8 1.57421875e+00 -3.4224165e-03 8 1.57421875e+00 -3.4224165e-03 9 1.57226563e+00 -1.4692977e-03 9 1.57226563e+00 -1.4692977e-03 10 1.57128906e+00 -4.9273519e-04 10 1.57128906e+00 -4.9273519e-04 11 1.57080078e+00 -4.4542051e-06 11 1.57080078e+00 -4.4542051e-06

Approximate solution P = 1.57080078Approximate solution P = 1.57080078

with F(P) = -.00000445with F(P) = -.00000445

Number of iterations = 11Number of iterations = 11

Tolerance = 5.00000000e-04 Tolerance = 5.00000000e-04

Page 33: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

alg025(); This is the Method of False alg025(); This is the Method of False

PositionPosition

Input the function F(x) in terms of xInput the function F(x) in terms of x

> cos(x)-x> cos(x)-x

Input endpoints Input endpoints P0 < P1P0 < P1 separated by a separated by a

blank spaceblank space0.5 0.78539816350.5 0.7853981635

Input toleranceInput tolerance

>0.0005>0.0005

Page 34: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Input maximum number of Input maximum number of iterations - no decimal pointiterations - no decimal point> 25> 25Select output destinationSelect output destination1. Screen1. Screen2. Text file2. Text fileEnter 1 or 2Enter 1 or 2>1>1

Page 35: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Select amount of outputSelect amount of output1. Answer only1. Answer only2. All intermediate 2. All intermediate approximationsapproximationsEnter 1 or 2Enter 1 or 2> 2> 2

Page 36: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

METHOD OF FALSE POSITION METHOD OF FALSE POSITION I P F(P)I P F(P) 2 7.36384139e-01 4.51771860e-032 7.36384139e-01 4.51771860e-03 3 7.39058139e-01 4.51772000e-053 7.39058139e-01 4.51772000e-05 4 7.39084864e-01 4.50900000e-074 7.39084864e-01 4.50900000e-07

Approximate solution P = .73908486Approximate solution P = .73908486with F(P) = .00000045with F(P) = .00000045Number of iterations = 4 Number of iterations = 4 Tolerance = 5.00000000e-04Tolerance = 5.00000000e-04

Page 37: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

System of System of Linear Linear

EquationsEquations

System of System of Linear Linear

EquationsEquations

Page 38: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Gaussian Elimination Gauss-Jordon EliminationCrout’s Reduction Jacobi’sGauss- Seidal Iteration RelaxationMatrix Inversion

Gaussian Elimination Gauss-Jordon EliminationCrout’s Reduction Jacobi’sGauss- Seidal Iteration RelaxationMatrix Inversion

Page 39: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

> alg061();> alg061();This is Gaussian Elimination to solve a This is Gaussian Elimination to solve a linear system.linear system.The array will be input from a text file in The array will be input from a text file in the order:the order:A(1,1), A(1,2), ..., A(1,N+1), A(2,1), A(1,1), A(1,2), ..., A(1,N+1), A(2,1), A(2,2), ..., A(2,N+1),..., A(N,1), A(N,2), ..., A(2,2), ..., A(2,N+1),..., A(N,1), A(N,2), ..., A(N,N+1)A(N,N+1)

Place as many entries as desired on each Place as many entries as desired on each line, but separate entries withline, but separate entries withat least one blank.at least one blank.

Page 40: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Has the input file been created? - enter Y or N.Has the input file been created? - enter Y or N.> y> yInput the file name in the form - drive:\Input the file name in the form - drive:\name.extname.extfor example: A:\DATA.DTAfor example: A:\DATA.DTA> d:\maple00\dta\alg061.dta> d:\maple00\dta\alg061.dtaInput the number of equations - an integer.Input the number of equations - an integer.> 4> 4Choice of output method:Choice of output method:1. Output to screen1. Output to screen 2. Output to text file2. Output to text filePlease enter 1 or 2.Please enter 1 or 2.> 1> 1

Page 41: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

GAUSSIAN ELIMINATIONGAUSSIAN ELIMINATION

The reduced system - output by rows:The reduced system - output by rows: 1.00000000 -1.00000000 2.00000000 -1.00000000 -8.000000001.00000000 -1.00000000 2.00000000 -1.00000000 -8.00000000

0.00000000 2.00000000 -1.00000000 1.00000000 6.000000000.00000000 2.00000000 -1.00000000 1.00000000 6.00000000

0.00000000 0.00000000 -1.00000000 -1.00000000 -4.000000000.00000000 0.00000000 -1.00000000 -1.00000000 -4.00000000

0.00000000 0.00000000 0.00000000 2.00000000 4.000000000.00000000 0.00000000 0.00000000 2.00000000 4.00000000

Has solution vector:Has solution vector: -7.00000000 3.00000000 2.00000000 2.00000000-7.00000000 3.00000000 2.00000000 2.00000000

with 1 row interchange (s)with 1 row interchange (s)

Page 42: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

> alg071();> alg071();This is the Jacobi Method for Linear This is the Jacobi Method for Linear Systems.Systems.The array will be input from a text file The array will be input from a text file in the orderin the orderA(1,1), A(1,2), ..., A(1,n+1), A(2,1), A(1,1), A(1,2), ..., A(1,n+1), A(2,1), A(2,2), ..., A(2,2), ..., A(2,n+1),..., A(n,1), A(n,2), ..., A(n,n+1)A(2,n+1),..., A(n,1), A(n,2), ..., A(n,n+1)Place as many entries as desired on Place as many entries as desired on each line, but separateeach line, but separateentries with at least one blank.entries with at least one blank.

Page 43: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

The initial approximation should follow The initial approximation should follow in the same format has the input file in the same format has the input file been created? - enter Y or N.been created? - enter Y or N.> y> yInput the file name in the form - drive:\Input the file name in the form - drive:\name.extname.extfor example: A:\DATA.DTAfor example: A:\DATA.DTA> d:\maple00\alg071.dta> d:\maple00\alg071.dtaInput the number of equations - an Input the number of equations - an integer.integer.> 4> 4

Page 44: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Input the tolerance.Input the tolerance.

> 0.001> 0.001

Input maximum number of iterations.Input maximum number of iterations.

> 15> 15

Choice of output method:Choice of output method:

1. Output to screen1. Output to screen

2. Output to text file2. Output to text file

Please enter 1 or 2.Please enter 1 or 2.

> 1> 1

Page 45: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

JACOBI ITERATIVE METHOD JACOBI ITERATIVE METHOD FOR LINEAR SYSTEMSFOR LINEAR SYSTEMS

The solution vector is :The solution vector is :1.00011860 1.99976795 1.00011860 1.99976795 -.99982814 0.99978598-.99982814 0.99978598using 10 iterationsusing 10 iterationswith Tolerance 1.0000000000e-03with Tolerance 1.0000000000e-03

Page 46: Lecture 44 Numerical Analysis. Solution of Non-Linear Equations

Lecture 44Lecture 44

NumericalAnalysis

NumericalAnalysis