False Position Method
False position method:
This is the oldest method for finding the real root of a nonlinear equation f(x) = 0 and closely resembles the bisection method. In this method, also known as regula falsi or the method of chords, we choose two points a and b such that f(a) and f(b) are of opposite signs. Hence, a root must lie in between these points. A root must lie in between these points. Now, the equation of the chord joining the two points [a, f(a)] and [b, f(b)] is given by
[y − f(a)]/ [x − a] = [f(b) − f(a)]/ [b − a] ................................(1)
The method consists in replacing the part of the curve between the points [a, f(a)] and [b, f(b)] by means of the chord joining these points, and taking the point of intersection of the chord with the x-axis as an approximation to the root. The point of intersection in the present case is obtained by putting y = 0 in Eq. (1). Thus, we obtain
x1 = {f(a)/ [f(b) − f(a)]} (b − a) = [a f(b) − bf(a)] / [f(b) − f(a)] ....................................(2)
which is the first approximation to the root of f(x) = 0. If now f(x1) and f(a) are of opposite signs, then the root lies between a and x1, and we replace b by x1 in Eq. 2, and obtain the next approximation. Otherwise, we replace a by x1 and generate the next approximation.
The procedure is repeated till the root is obtained to the desired accuracy.
Python Program For False Position Method/ Regula Falsi Method:
import math
# ------------------ equation - ----- ----- ---- ----- --
def func ( x):
# return 5* math . exp (-x) + x - 5 # wien constant case
return 4* math . exp (x) * math . sin (x) -1
# ---------- false postion method - ----- ----- ---- ----
def false_postion (a , b , max_iter ):
if ( func (a ) * func (b) >= 0) :
print (" you have not choosen right range of a and b \n")
return
c = a # inital assume / result
for i in range ( max_iter ) : #1
c = ( a * func (b) - b * func (a ))/ ( func (b) - func (a ))
# checking if the above point is over root or not
if ( func ( c) == 0) :
break # c is our root of equation
elif ( func (c) * func ( a) < 0) :
b = c # [a, c]
else :
a = c #[c, b]
print (" the value of x is : ", c)
# -----------------------------------------
a = -1
b = 1
max_iter = 50
false_postion (a , b , max_iter )
# -----------------------------------------
Comments
Post a Comment