Docsity

Regula Falsi method Python, Assignments of Computer Numerical Control

Toggle sidebar
bg1
'Regula Falsi Method'
import numpy as np
import matplotlib.pyplot as plt
import math
def f(x):
y=(2**x)-(x**2)
return y
print('Kindly Enter Value of X1: ')
X1= input()
print('Kindly Enter Value of X2: ')
X2= input()
X1= int(X1)
X2= int(X2)
for i in range (20):
if (f(X1)*f(X2)<=0):
X3=( X2-(((f(X2))*(X2-X1))/((f(X2))-(f(X1)))))
if(f(X3)<0):
X1=X3
print(X1)
else:
X2=X3
print(X2)
elif (f(X1)*f(X2)>=0):
X3=( X2-(((f(X2))*(X2-X1))/((f(X2))-(f(X1)))))
if(f(X3)<0):
X1=X3
print(X1)
else:
X2=X3
print(X2)
else:
print('Kindly Change the values of X1 and X2 !')

Partial preview of the text

Download Regula Falsi method Python and more Assignments Computer Numerical Control in PDF only on Docsity!

'Regula Falsi Method' import numpy as np import matplotlib.pyplot as plt import math def f(x): y=( 2 x)-(x 2 ) return y print('Kindly Enter Value of X1: ') X1= input() print('Kindly Enter Value of X2: ') X2= input() X1= int(X1) X2= int(X2) for i in range ( 20 ): if (f(X1)f(X2)<= 0 ): X3=( X2-(((f(X2))(X2-X1))/((f(X2))-(f(X1))))) if(f(X3)< 0 ): X1=X print(X1) else: X2=X print(X2) elif (f(X1)f(X2)>= 0 ): X3=( X2-(((f(X2))(X2-X1))/((f(X2))-(f(X1))))) if(f(X3)< 0 ): X1=X print(X1) else: X2=X print(X2) else: print('Kindly Change the values of X1 and X2 !')