## Question

## Transcribed Text

By purchasing this solution you'll be able to access the following files:

Solution.py.

Write a program that finds roots of a nonlinear equation:
1) Create a Python function, "falsepos(func lb, ub, tolf)", that calculates the root of a function
using the false position method given the function name (func), a lower bound (lb), an upper
bound (ub), and a tolerance on the value of the equation (tolf) for stopping criteria. The function
should return the calculated root and the number of iterations.
2) Create a Python function, "bisect (func, lb, ub, tolf)", that calculates the root of a function
using the Bisection method given the function name (func), a lower bound (lb), an upper bound
(ub), and a tolerance on the value of the equation (tolf) for stopping criteria. The function
should return the calculated root and the number of iterations.
Use your Python functions to find the roots of the following equations in the interval of
x €[-1,1.5]:
a) x tan(x) = 2
b) cos(x) = x
c) x3 + sin(x) + cos(x) = 0,
Compare the results and the number of iterations for the two methods. Set the stopping criterion
for your equation as If(x)l < of where of = 10-3.
Challenge:
Modify your functions to output the result at each iteration for false position method and Bisection
method. Make a graph of the relative errors vs iteration number for the two methods and compare
their convergence behavior.
For a given value of a and its approximation aapp, the relative error is defined as
Er = a dapp
a
For your calculations consider a as the root found from your function and aapp as the value
calculated at each iteration.
For example, if you use your functions to find the root of x3 - 8 = 0 in the interval of x € [0, 3]
(Ib = 0, ub = 3, tolf = 0.01, x0 = 4), your program should produce a figure similar to
Bisection
False position
50
40
30
20
10
2
4
6
8
10
iteration number

By purchasing this solution you'll be able to access the following files:

Solution.py.

Get College Homework Help.

**Are you sure you don't want to upload any files?**

Fast tutor response requires as much info as possible.

**Decision:**

Upload a file

Continue without uploading