In [128]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import scipy.optimize as opt
The following potential is often used in Physics and other fields to describe symmetry breaking and is often known as the "hat potential":
$$ V(x) = -a x^2 + b x^4 $$Write a function hat(x,a,b)
that returns the value of this function:
In [153]:
def hat(x, a, b):
return (-a * x**2 + b * x**4)
In [154]:
assert hat(0.0, 1.0, 1.0)==0.0
assert hat(0.0, 1.0, 1.0)==0.0
assert hat(1.0, 10.0, 1.0)==-9.0
Plot this function over the range $x\in\left[-3,3\right]$ with $b=1.0$ and $a=5.0$:
In [145]:
a = 5.0
b = 1.0
x = np.linspace(-3, 3, 100)
In [136]:
plt.plot(x, hat(x, a, b))
Out[136]:
In [93]:
assert True # leave this to grade the plot
Write code that finds the two local minima of this function for $a=5.0$ and $b=1.0$.
scipy.optimize.minimize
to find the minima. You will have to think carefully about how to get this function to find both minima.
In [149]:
minima = opt.minimize(hat, x, args = (a, b))
In [95]:
assert True # leave this for grading the plot
To check your numerical results, find the locations of the minima analytically. Show and describe the steps in your derivation using LaTeX equations. Evaluate the location of the minima using the above parameters.
Equation we began with:
Minima and maxima occur where the first derivatives are equal to 0. Differentiating with respect to x, factoring, and setting to 0 yields:
Assuming a = 5 and b = 1:
We get:
In the second equation, solving for x yields:
Therefore, there is a minina or maxima at:
To determine which values are minima or maxima, we plug them back into the original equation and compare their values:
Therefore there exists 2 minima at: