Senior Fresh Computational Physics Laboratory Report
Laboratory 1: Finding minima of functions
Samuel Power
October 21, 2025
1 Introduction
Why is it important to define the stable equilibrium of a potential energy function? The
importance of this is often understated but can be summarized as follows: ”the force
associated with the potential energy function points towards the equilibrium point” [1] .
What this means in essence is that when we displace a particle a small distance from
equilibrium and it reaches stable equilibrium, it will return to the original equilibrium.
In the project I undertook we used different methods of root finding. Why did I do this
you might ask? To find where a potential energy function is in stable equilibrium, we
must first find where its first derivative is zero, so we are doing the same process, only
finding where f (x) = 0, instead of f ′ (x) = 0.
Finally, I took our root finding skills and applied it to a potential energy problem. In
order to be in a stable equilibrium, not only does your first derivative have to be equal
to zero, but your second derivative has to be positive as well.
2 Methodology
Firstly, I used different root finding methods and compared in order to decipher which
was most accurate.
• The bisection method of root finding was the first I used. The process of root
finding was very trial and error. I picked an arbitrary function with two integer
1
roots then the process is as follows. I picked two points around the root, x1 and x3 ,
where f (x1 ) < 0 and f (x3 ) > 0. In order to find the root I continually decreased
the interval.
• Next, I evaluated the midpoint of the interval, f (x2 ). Why I did this is because we
can actually evaluate a lot based off our midpoint. If the value of this midpoint is
greater than zero, the root must lie between x1 and x2 , so we can replace x3 with
x2 , and vice versa.
• Finally, I repeated this process until the value of |(f (x2 )| < tol, where tol is a small
value (tolerance) that I was given in the assignment[2] .
The other root finding method that I used was the Newton-Raphson root finding method.
This method works as follows:
• This method is based off the Taylor expansion for a function, i.e., f (a + h) =
f (a) + hf ′ (a) + (h2 /2!) ∗ (f ′′ (a)) + ....
• When we are using the method a is the current estimate of our root, and h is the
desired step direction in which we wish to go.
• I needed a linear equation to solve in order for us to get a better approximation of
the root. How do I go about doing this?
• I did this by cutting off any terms in the Taylor expansion that are not linear in
h. This leaves us with f (a + h) = f (a) + hf ′ (a) + O(h2 ). The O(h2 ) means we
simply do not include any terms h2 or higher in the expansion.
• Since f (a + h) is an approximation for a root, we can set it to zero (similar to
f (x) = 0).
.
• We get f (a) + hf ′ (a) = 0. Rearranging, we obtain h = − ff′(a)
(a)
• We want a + h, as this is the root f (a + h) that we are trying to find, so we have
[2]
a + h = a − ff′(a)
.
(a)
• This gives us our improved root estimate.
Finally, I put my root finding skills to the test and evaluated a potential energy function.
I studied the potential energy of the interaction between two ions as follows:
x
2
e
• The function we are evaluating was given as, V (x) = Ae− p − 4πε
.
0x
2
e
• We were given the respective values of A, 4πε
, and p in their respective units.
0x
• We used a variation of the Newton-Raphson method, solving for first derivative
instead of root.
′
• x1 = x1 − VV ′′(x(x11) .
• We can then use that formula to find the potential energy minimum, and thus find
the stable equilibrium
2
2.1 What do we Hope to Achieve?
• Compare root finding methods (bisection and Newton-Raphson), and come to
conclusions over which is more efficient in certain scenarios.
• Evaluate different types of code for root finding methods.
• Use our evaluation of root finding methods and find the most efficient methods for
finding stable equilibrium of potential energy functions.
• Evaluate the physics behind a stable equilibrium of a potential energy function
and interpret what this means.
These points will be dissected in the results and conclusions sections of the report.
3 Results
3.1 Root Finding: Bisection Method
This is how I carried out the Bisection Method.
• Firstly, I had to choose an arbitrary function in order to be able to find its roots.
I chose f (x) = x2 − x − 6. Just by observation, we can see that the roots are
x = 3, −2.
• I first chose to find the x = 3 root by the bisection method. I chose my two points,
x1 = 2 and x3 = 4. I used basic matplotlib terminology to obtain the basis of my
graph (figure 1).
• I used an if loop to begin the narrowing of the interval of x1 and x3 and obtain
the correct value for x2 .
• I later used the same if loop and same principles to obtain the x5 root (narrow
interval of x5 and x6 ).
• I then implemented my tol (tolerance), iterated into a ’while’ loop to count the
number of times the operations had to occur to get an accurate root within the
tolerance (tol = 0.0001 originally).
• The same as above, we implemented our second root (x5 = −2 into the same while
loop to count the number of steps (’nsteps’) it took to obtain the roots within the
desired tolerance.
• Eventually, as per guidelines, I experimented with different values of tolerance,
graphing the results as nsteps versus ’np.log10(tol)’.
3
Figure 3.1:
Using the above method, continually decreasing the width of the intervals of the original
points picked, and then iterating the while loop until we had our roots within the desired
tolerance, I obtained the two roots, x2 = 3 and x5 = 0 within a range of 0.0001. The
results can be seen above in Figure 3.1.
Figure 3.2:
In Figure 3.2 above, we have our graph of ’nsteps’ versus ’log10(tol)’. The purpose of
4
the log10 is so that we can convert an exponential graph into a linear one and interpret
neat results. The interpretation of this graph is that the smaller our tolerance gets, the
higher the number of iterations we need to get our root to within the desired tolerance.
Here is a tabulated version of Figure 3.2.
Convergence of bisection method
Tolerance
Number of iterations needed
−1
10
8
−2
10
11
10−3
14
−4
10
18
−5
10
21
10−6
24
−7
10
29
As we can see from the above graph, as we make the tolerance smaller and smaller, the
number of iterations needed increases somewhat linearly. A further interpretation and
comparison to Newton-Raphson is in the conclusion.
3.2 Root Finding: Newton-Raphson Method
This is how I carried out the Newton-Raphson Method.
• We began by evaluating the same function as in the Bisection Method.
• In this variant of root finding, I had to evaluate the derivative of the function
itself, so I simply had to code in a derivative function ( f (x) = ax2 + bx + c and
f ′ (x) = 2ax+b. The variation between the two is that the ’c’ parameter disappears
in the derivative function.
• Next I initialized an initial guess for the root, x1 = 1.
1)
.
• As is the basis of the method itself, x1 is updated by the formula x1 = x1 − ff′(x
(x1 )
• I again implemented a ’while’ loop to iterate the formula while the value of the
root was above the desired tolerance (tol = 0.0001).
• As was the same with the Bisection Method, I varied the value of ’tol’ and obtained
a graph that illustrates the linear relationship between ’nsteps’ and ’log10(tol)’.
5
Figure 3.3:
Figure 3.4:
Trivially, the roots found by the two methods have the same results. This can be seen
above in Figure 3.3.
6
Figure 3.4 is appropriately named as ’Convergence of Newton-Raphson Method’. As
the values of the tolerance get smaller, the curve completely converges to the value
nsteps = 4.00.
I have included a tabulated version of the results below.
Convergence of Newton-Raphson method
Tolerance
Number of iterations needed
−1
10
2
−2
10
3
10−3
3
−4
10
4
−5
10
4
10−6
4
−7
10
4
The tabulated data outlines what we can see from the graph, the tolerance appears to
converge at nsteps = 4.
Potentially, with an extremely small tolerance the number of steps could increase slightly,
but I did not choose to output that in my code.
An interpretation of this could be that the Newton-Raphson method does not require
an extremely small tolerance, the root will come to the same output with a relatively
large tolerance, such as tol = 0.0001.
3.3 Finding the minima roots of a potential energy
function
Finally, I put my root finding skills to the test and applied them to a potential energy
function.
• Evaluating the potential
energy function was relatively simplistic. I took the funcx
e2
tion, V (x) = Ae− p − 4πε
, and evaluated it for a range of x values from 0.01 to
0x
1.00, in intervals of 0.001.
• I was enabled to do this using the np.linspace tool on python.
• I differentiated the function by hand to obtain V ′ (x) and then created a new
function F (x) = −V ′ (x) to evaluate the force acting on the particle at a given
point.
• I then differentiated V ′ (x) to obtain V ′′ (x) and then implemented the Newton′
Raphson method: x1 = x1 − VV ′′(x(x11) .
• In order for the potential energy to be at a minimum, we need F (x) = 0, this point
is shown in the plot below.
7
• The shape of our potential energy graph V (x) will give us an insight into how the
potential energy of a particle changes with position, and the slope of this graph,
F (x) will tell us the force on the particle.
• Both graphs are shown below.
Figure 3.5:
From Figure 3.5, Vmin = −5.247489118537514. The physical interpretation of this is
that this is the lowest potential energy a particle can have. Vmin occurs at xmin , where
xmin = 0.23605374668661516. As we can see from Figure 3.6 below (For some reason
this graph is outputting in the middle of the conclusion section), F (x) = 0 at this point
(approximately). This represents our point of stable equilibrium.
As we can see from Figure 3.6, at xmin , F (x) = 0.00005739156378581356, which is
approximately zero, so we have found our stable equilibrium point using the NewtonRaphson method.
4 Conclusions
Based off the research I have done, I have come to the following conclusions:
• Based off my results, it appears to me that the Newton-Raphson method for root
finding is more accurate than the bisection method. It takes less iterations to
obtain results within the desired tolerance and it also converges at tol = 0.00001.
Whereas, for the bisection method, I did not reach a conclusion as to where the
8
Figure 3.6:
convergence actually occurs as I would have had to iterate the code many more
times.
• One issue with the Newton-Raphson method is when the second derivative is zero,
which means that the function cannot be evaluated.
• The Newton-Raphson method is also easier to interpret when doing work by hand
than the bisection method, but both are relatively trivial.
• The interpretation of the potential energy function is quite interesting. We can use
the methods described in the method and results to evaluate any potential energy
function, and use it to find its stable equilibrium. One such example is Hooke’s
Law, Fx = −kx.
• A simple variation of Newton-Raphson enabled us to evaluate the function.
• I needed the information from both the potential energy graph and the force graph
to obtain the stable equilibrium. The potential energy graph enables us to find the
point where the potential energy is at a minimum, while the force graph allows us
to see that the force at that point is zero.
• In conclusion, given a small infinitesimal displacement, the restoring force pulls
that particle back to the equilibrium position when we have stable equilibrium.
9
5 References
1. Physics LibreTexts: 8.10: Potential Energy Diagrams and Stability - Physics LibreTexts.
2. Lab 1: Minima of Functions Overview, Trinity College Dublin
10