math306&307 - neumerical analysis - lec 2 - regula falsi

32
Math 306,307 - Programming & Numerical Methods Numerical Analysis through Fortran90 and C++ Sqn Ldr Athar Kharal Humanities and Science Department College of Aeronautical Engineering PAF Academy Risalpur Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scientic Computing 1/8

Upload: hamza-ashraf

Post on 18-Feb-2016

223 views

Category:

Documents


2 download

DESCRIPTION

numerical methods

TRANSCRIPT

Page 1: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Math 306,307 - Programming & Numerical MethodsNumerical Analysis through Fortran90 and C++

Sqn Ldr Athar Kharal

Humanities and Science DepartmentCollege of Aeronautical Engineering

PAF Academy Risalpur

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 1 / 8

Page 2: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

NotationFor the sake of brevity we may write f (x0) as f0 or y0 and in general f (xi )as fi or yi . Henceforth both the notations may be used interchangeably.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 2 / 8

Page 3: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Root Finding by Regula Falsi

Root Finding: Regula Falsi MethodRegula Falsi Method repeatedly uses a false position of the root. Thismethod is also known as

False Position Method or

Linear Interpolation Method or

Method of Chords.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 3 / 8

Page 4: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Root Finding by Regula Falsi

Root Finding: Regula Falsi MethodRegula Falsi Method repeatedly uses a false position of the root. Thismethod is also known as

False Position Method or

Linear Interpolation Method or

Method of Chords.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 3 / 8

Page 5: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Root Finding by Regula Falsi

Root Finding: Regula Falsi MethodRegula Falsi Method repeatedly uses a false position of the root. Thismethod is also known as

False Position Method or

Linear Interpolation Method or

Method of Chords.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 3 / 8

Page 6: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Derivation of Regula FalsiThis method is similar to Bisection Method but, instead of �nding themidpoint between x1 and x2 it calculates x0 by linear interpolation.

Thepoint of intersection x0 of the chord connecting the points (x1, y1) &(x2, y2) with the x-axis is calculated from the equation of the straight line(the chord joining the two points),

(x � x1)(y � y1)

=(x2 � x1)(y2 � y1)

where y1 = f1 = f (x1) and y2 = f2 = f (x2) . Hence

(y � y1)(x � x1)

=(y2 � y1)(x2 � x1)

or(y � f1)(x � x1)

=(f2 � f1)(x2 � x1)

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 4 / 8

Page 7: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Derivation of Regula FalsiThis method is similar to Bisection Method but, instead of �nding themidpoint between x1 and x2 it calculates x0 by linear interpolation. Thepoint of intersection x0 of the chord connecting the points (x1, y1) &(x2, y2) with the x-axis is calculated from the equation of the straight line(the chord joining the two points),

(x � x1)(y � y1)

=(x2 � x1)(y2 � y1)

where y1 = f1 = f (x1) and y2 = f2 = f (x2) . Hence

(y � y1)(x � x1)

=(y2 � y1)(x2 � x1)

or(y � f1)(x � x1)

=(f2 � f1)(x2 � x1)

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 4 / 8

Page 8: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Derivation of Regula FalsiThis method is similar to Bisection Method but, instead of �nding themidpoint between x1 and x2 it calculates x0 by linear interpolation. Thepoint of intersection x0 of the chord connecting the points (x1, y1) &(x2, y2) with the x-axis is calculated from the equation of the straight line(the chord joining the two points),

(x � x1)(y � y1)

=(x2 � x1)(y2 � y1)

where y1 = f1 = f (x1) and y2 = f2 = f (x2) .

Hence

(y � y1)(x � x1)

=(y2 � y1)(x2 � x1)

or(y � f1)(x � x1)

=(f2 � f1)(x2 � x1)

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 4 / 8

Page 9: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Derivation of Regula FalsiThis method is similar to Bisection Method but, instead of �nding themidpoint between x1 and x2 it calculates x0 by linear interpolation. Thepoint of intersection x0 of the chord connecting the points (x1, y1) &(x2, y2) with the x-axis is calculated from the equation of the straight line(the chord joining the two points),

(x � x1)(y � y1)

=(x2 � x1)(y2 � y1)

where y1 = f1 = f (x1) and y2 = f2 = f (x2) . Hence

(y � y1)(x � x1)

=(y2 � y1)(x2 � x1)

or(y � f1)(x � x1)

=(f2 � f1)(x2 � x1)

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 4 / 8

Page 10: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Derivation of Regula FalsiThis method is similar to Bisection Method but, instead of �nding themidpoint between x1 and x2 it calculates x0 by linear interpolation. Thepoint of intersection x0 of the chord connecting the points (x1, y1) &(x2, y2) with the x-axis is calculated from the equation of the straight line(the chord joining the two points),

(x � x1)(y � y1)

=(x2 � x1)(y2 � y1)

where y1 = f1 = f (x1) and y2 = f2 = f (x2) . Hence

(y � y1)(x � x1)

=(y2 � y1)(x2 � x1)

or(y � f1)(x � x1)

=(f2 � f1)(x2 � x1)

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 4 / 8

Page 11: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Since the chord intersects the x-axis at x0 and y = 0, we have

(f2 � f1)(x2 � x1)

=(0� f1)(x � x1)

or x0 � x1 = � f1 (x2 � x1)f2 � f1

Hence

x0 = x1 �f (x2 � x1)f2 � f1

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 5 / 8

Page 12: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Since the chord intersects the x-axis at x0 and y = 0, we have

(f2 � f1)(x2 � x1)

=(0� f1)(x � x1)

or x0 � x1 = � f1 (x2 � x1)f2 � f1

Hence

x0 = x1 �f (x2 � x1)f2 � f1

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 5 / 8

Page 13: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Since the chord intersects the x-axis at x0 and y = 0, we have

(f2 � f1)(x2 � x1)

=(0� f1)(x � x1)

or x0 � x1 = � f1 (x2 � x1)f2 � f1

Hence

x0 = x1 �f (x2 � x1)f2 � f1

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 5 / 8

Page 14: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Since the chord intersects the x-axis at x0 and y = 0, we have

(f2 � f1)(x2 � x1)

=(0� f1)(x � x1)

or x0 � x1 = � f1 (x2 � x1)f2 � f1

Hence

x0 = x1 �f (x2 � x1)f2 � f1

.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 5 / 8

Page 15: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 16: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.

3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 17: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 18: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.

5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 19: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 1

6 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 20: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 0

7 Compute x0 = x1 � f (x2�x1)f2�f1 and f0

8 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 21: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f0

8 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 22: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 23: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 10

10 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 24: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Algorithm for Regula Falsi Method1 Choose two initial estimates of one of the roots in its vicinity andtolerance δ.

2 Compute f1 and f2.3 If jf1j � δ then root = x1; Step 10.ElseIf jf2j � δ then root = x2; Step 10.

4 If f1 � f2 > 0 then Print �Root not in this range�; Step 10.5 count = 16 While count 6= 07 Compute x0 = x1 � f (x2�x1)

f2�f1 and f08 If f0 � f2 � 0 then x2 = x0 and f2 = f0; count = count+1;elsex1 = x0 and f1 = f0; count = count+1;

9 If jf0j � δ then write value of the root; count=0; Step 1010 Stop.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 6 / 8

Page 25: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Example

We evaluate the root of f (x) = x2 � 16 using Regula Falsi Method as:

Iteration No x1 x2 x0

f1 f2 f0Initialization 3.0000 4.5000 3.9330 �7.0000 4.2500 �0.5315

x1 x0 1 3.9330 4.5000 3.9956 �0.5315 4.2500 �0.0351

x1 x0 2 3.9956 4.5000 3.9997 �0.0317 4.2500 �0.0023

x1 x0 3 3.9997 4.5000 3.9999 �0.0021 4.2500 �0.0008

Hence the root isx0 = 3.9999.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 7 / 8

Page 26: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Example

We evaluate the root of f (x) = x2 � 16 using Regula Falsi Method as:

Iteration No x1 x2 x0 f1 f2 f0

Initialization 3.0000 4.5000 3.9330 �7.0000 4.2500 �0.5315

x1 x0 1 3.9330 4.5000 3.9956 �0.5315 4.2500 �0.0351

x1 x0 2 3.9956 4.5000 3.9997 �0.0317 4.2500 �0.0023

x1 x0 3 3.9997 4.5000 3.9999 �0.0021 4.2500 �0.0008

Hence the root isx0 = 3.9999.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 7 / 8

Page 27: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Example

We evaluate the root of f (x) = x2 � 16 using Regula Falsi Method as:

Iteration No x1 x2 x0 f1 f2 f0Initialization 3.0000 4.5000 3.9330 �7.0000 4.2500 �0.5315

x1 x0 1 3.9330 4.5000 3.9956 �0.5315 4.2500 �0.0351

x1 x0 2 3.9956 4.5000 3.9997 �0.0317 4.2500 �0.0023

x1 x0 3 3.9997 4.5000 3.9999 �0.0021 4.2500 �0.0008

Hence the root isx0 = 3.9999.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 7 / 8

Page 28: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Example

We evaluate the root of f (x) = x2 � 16 using Regula Falsi Method as:

Iteration No x1 x2 x0 f1 f2 f0Initialization 3.0000 4.5000 3.9330 �7.0000 4.2500 �0.5315

x1 x0 1 3.9330 4.5000 3.9956 �0.5315 4.2500 �0.0351

x1 x0 2 3.9956 4.5000 3.9997 �0.0317 4.2500 �0.0023

x1 x0 3 3.9997 4.5000 3.9999 �0.0021 4.2500 �0.0008

Hence the root isx0 = 3.9999.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 7 / 8

Page 29: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Example

We evaluate the root of f (x) = x2 � 16 using Regula Falsi Method as:

Iteration No x1 x2 x0 f1 f2 f0Initialization 3.0000 4.5000 3.9330 �7.0000 4.2500 �0.5315

x1 x0 1 3.9330 4.5000 3.9956 �0.5315 4.2500 �0.0351

x1 x0 2 3.9956 4.5000 3.9997 �0.0317 4.2500 �0.0023

x1 x0 3 3.9997 4.5000 3.9999 �0.0021 4.2500 �0.0008

Hence the root isx0 = 3.9999.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 7 / 8

Page 30: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Example

We evaluate the root of f (x) = x2 � 16 using Regula Falsi Method as:

Iteration No x1 x2 x0 f1 f2 f0Initialization 3.0000 4.5000 3.9330 �7.0000 4.2500 �0.5315

x1 x0 1 3.9330 4.5000 3.9956 �0.5315 4.2500 �0.0351

x1 x0 2 3.9956 4.5000 3.9997 �0.0317 4.2500 �0.0023

x1 x0 3 3.9997 4.5000 3.9999 �0.0021 4.2500 �0.0008

Hence the root

isx0 = 3.9999.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 7 / 8

Page 31: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Example

We evaluate the root of f (x) = x2 � 16 using Regula Falsi Method as:

Iteration No x1 x2 x0 f1 f2 f0Initialization 3.0000 4.5000 3.9330 �7.0000 4.2500 �0.5315

x1 x0 1 3.9330 4.5000 3.9956 �0.5315 4.2500 �0.0351

x1 x0 2 3.9956 4.5000 3.9997 �0.0317 4.2500 �0.0023

x1 x0 3 3.9997 4.5000 3.9999 �0.0021 4.2500 �0.0008

Hence the root isx0 = 3.9999.

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 7 / 8

Page 32: Math306&307 - Neumerical Analysis - Lec 2 - Regula Falsi

Thank you

Sqn Ldr Athar Kharal (H and S, CAE) Fundamentals of Scienti�c Computing 8 / 8