Regula Falsi method Python, Assignments of Computer Numerical Control

It contains the numerical analysis method named reglua falsi or false position method python code with its output

Typology: Assignments

2019/2020

Uploaded on 04/17/2020

naveed-alei-shah
naveed-alei-shah 🇵🇰

4.5

(2)

1 document

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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 !')