# ## Finding Roots of Equations: Introduction and Graphical Methods

Let be a function. One of the most basic problems in numerical analysis is to find the value that would render . This value is called a root of the equation . As an example, consider the function . Consider the equation . Clearly, there is only one root to this equation which is . Alternatively, consider defined as with . There are two analytical roots for the equation given by In this section we are going to present three classes of methods: graphical, bracketing, and open methods for finding roots of equations.

### Graphical Methods

Graphical methods rely on a computational device that calculates the values of the function along an interval at specific steps, and then draws the graph of the function. By visual inspection, the analyst can identify the points at which the function crosses the axis. Graphical methods are very useful for one-dimensional problems, but for multi-dimensional problems it is not possible to visualize a graph of a function of multi-variables.

##### Example

As an example, consider . We wish to find the values of (i.e., the roots) that would satisfy the equation for . The fastest way is to plot the graph (even Microsoft Excel would serve as an appropriate tool here) and then visually inspect the locations where the graph crosses the axis: As shown in the above graph, the equation has three roots and just by visual inspection, the roots are around , , and . Of course these estimates are not that accurate for , , and . Whether these estimates are acceptable or not, depends on the requirements of the problem. We can further zoom in using the software to try and get better estimates: Visual inspection of the zoomed-in graphs provides the following estimates: , , and which are much better estimates since: , , and View Mathematica Code
Clear[x]
f = Sin[5 x] + Cos[2 x]
Plot[f, {x, -1, 1}, AxesLabel -> {"x", "f"}]
f /. x -> -0.525
f /. x -> -0.21
f /. x -> 0.675
Plot[f, {x, -0.53, -0.52}, AxesLabel -> {"x", "f"}]
Plot[f, {x, -0.25, -0.2}, AxesLabel -> {"x", "f"}]
Plot[f, {x, 0.66, 0.675}, AxesLabel -> {"x", "f"}]
f /. x -> -0.5235
f /. x -> -0.225
f /. x -> 0.6731

View Python Code
import numpy as np
import matplotlib.pyplot as plt

def f(x): return np.sin(5*x) + np.cos(2*x)

x1 = np.arange(-1,1,0.01)
plt.plot(x1,f(x1))
plt.xlabel('x'); plt.ylabel('f')
plt.grid(); plt.show()

print("f(-0.525):",f(-0.525))
print("f(-0.21):",f(-0.21))
print("f(0.675):",f(0.675))

x2 = np.arange(-0.53, -0.52,0.01)
plt.plot(x2,f(x2))
plt.xlabel('x'); plt.ylabel('f')
plt.grid(); plt.show()

x3 = np.arange(-0.25, -0.2,0.01)
plt.plot(x3,f(x3))
plt.xlabel('x'); plt.ylabel('f')
plt.grid(); plt.show()

x4 = np.arange(0.66, 0.675,0.01)
plt.plot(x4,f(x4))
plt.xlabel('x'); plt.ylabel('f')
plt.grid(); plt.show()

print("f(-0.5235):",f(-0.5235))
print("f(-0.225):",f(-0.225))
print("f(0.6731):",f( 0.6731))