Regula Falsi Method Or Method of false position
#Root of x**3-2*x-5 by regula fasli method-problem 2.6 sastry
from math import*
def f(x):
return (x**3-2*x-5)
a=2
b=3
x=(a*f(b)-b*f(a))/(f(b)-f(a))
print ("The successive approximation root is ")
while abs(f(x))>0.0000001:
x=(a*f(b)-b*f(a))/(f(b)-f(a))
print (x)
if f(x)<0:
a=x
elif f(x)>0:
b=x
#Correct root is 2.0945...
Output Screen:
The successive approximation root is
2.0588235294117645
2.0812636598450225
2.089639210090847
2.0927395743180055
2.0938837084618487
2.09430545112526
2.0944608457664873
2.0945180933857572
2.0945391822940174
2.094546950874257
2.094549812585823
2.0945508667513875
2.094551255072798
2.094551398118127
2.0945514508114953
2.0945514702220622
2.0945514773723
Comments
Post a Comment