Question: In the below code of Python implementation of Regula Falsi Method, the equation in return variable should be taken as input. The code should work

In the below code of Python implementation of Regula Falsi Method, the equation in return variable should be taken as input. The code should work for any type of equation as here we could just update in return variable so it should be taken as user input. Kindly update the code.

Code:

import math def f(x): return 2*x*math.cos(2*x)-(x+1)*(x+1) def RegularFalsi(x0,x1,e): Iteration = 1 condition = True while condition: x2 = x0 - (x1-x0) * f(x0)/( f(x1) - f(x0) ) print('Iteration-%d' % (Iteration)) print('x2 = %0.6f and f(x2) = %0.6f'% (x2, f(x2))) if f(x0) * f(x2) < 0: x1 = x2 else: x0 = x2 Iteration = Iteration + 1 condition = abs(f(x2)) > e print(' Required root is: %0.8f' % x2) x0 = input('Enter Value of a: ') x1 = input('Enter Value of b: ') e = input('Tolerable Error: ') x0 = float(x0) x1 = float(x1) e = float(e) if f(x0) * f(x1) > 0.0: print('Given guess values do not bracket the root.') print('Try Again with different guess values.') else: RegularFalsi(x0,x1,e)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!