Python Program for Regula Falsi Method

Python program for regula falsi method. This page provides program for regula falsi method in python programming language. To understand regula falsi method with definition, formula, example, graph, theory, advantages and disadvantages, application read Regula Falsi Method.

Example: Regula Falsi Method in Python

MAX_ITER = 1000000
def func( x ): 
	return (x * x * x - x * x + 2) 

def regula_falsi( number1 , number2): 
	if func(number1) * func(number2) >= 0: 
		print("You have not assumed right number1 and number2") 
		return -1
	
	root = number1
	
	for i in range(MAX_ITER): 
		

		root = (number1 * func(number2) - number2 * func(number1))/ (func(number2) - func(number1)) 
		

		if func(root) == 0: 
			break
		

		elif func(root) * func(number1) < 0: 
			number2 = root 
		else: 
			number1 = root 
	print("The value of root is : " , '%.4f' %root) 

number1 =-200
number2 = 300
regula_falsi(number1, number2)


Output:

The value of root is : -1

Comments