Exercise 15.5

Exercise 15.5#

Use all of the root finding methods of the scipy.optimize.root_scalar() function to find the roots of the following equations (with known roots provided):

Equation

Root Value

\((x - 2.75) (x + 7) = 0\)

\(2.75\)

\(\cos(x) - \sin(x) = 0\)

\(\tfrac{\pi}{4}\)

\((x - 5)^3 = 0\)

\(5\)

and compare the number of iterations each takes to find the root within an acceptable tolerance (this may be automatically selected by the function). Do this by using bar plots for each equation and method (arrange these as you see fit).

For initial guesses x0 and x1, use the same values as in the bracket argument. Make sure that the root value isn’t in the center of the bracket, as this may lead to the bracketing methods converging in one iteration, which isn’t a likely scenario in practice.