October 23, 2014 --- Class 17 --- Homework, AHO,
Numerical Integration in One Dimension
Homework
I discussed in detail how the homework was graded. We then
discussed how to simplify the approach to the anharmonic
oscillator.
Anharmonic Oscillator: Analytic Considerations
For homework you were asked to study the period of the
harmonic oscillator and how it depends on the force constant.
You were expected to find the period of oscillation for a number
values of k and to make a plot of period vs k. Having done that,
you were expected to determine the equation that corresponds to the
plot.
It turns out that a lot can be learned about this problem by
analytic means. We discussed how to use time translation to
get simple initial conditions. We then considered how we
could rescale x and t to simplify the equation of motion.
When we had done so, we found that we could determine the
dependence of the period on k, m and the initial amplitude,
up to a single unknown constant. This constant was the period
with unit mass, k and amplitude.
Here is some material about using Mathematica was not done in class:
Solving Differential Equations with Mathematica: Anharmonic Oscillator
If you have a simple differential equation to solve, you might want
to use Mathematica rather than a numerical code you develop yourself.
To solve a differential equation numerically, we use NDSolve. To solve
one analytically, use DSolve. For example:
s=NDSolve[ {x''[t] == - x[t]^3, x[0] == 1, x'[0] == 0}, x, {t, 0, 10}]
is the command required to solve the anharmonic oscillator with k/m=1.
x''[t] stands for the second derivative at time t. x'[0] stands for
the first derivative, or velocity, at t=0. Within the list that is
the first argument to NDSolve, we have the differential equation
itself and the initial conditions on position and velocity that are
required to specify the solution. The solution s will be an
"interpolating function" for x[t] over the range
0 <= t <= 10.
If your next command is
Plot[ Evaluate[x[t] /. s], {t, 0, 10}]
Mathematica will display a plot of the solution. The command
Evaluate[x[t] /. s] tells Mathematica to use the interpolating
function as a substitution rule and then to evaluate the
function x. You can find the solution at a
particular time with a command like:
x[7.5] /. s
I do not find the following commands intuitive, but they can be used
to find the period:
x /. First[s]
FindRoot[ %[t] == 1, {t, 7.5}]
The output of the first command is the interpolating function itself.
In the second command, % stands for the interpolating function, we
make it a function of t and then ask Mathematica to find the value of
t that makes the function 1. We have the search start near 7.5 because
looking at the plot of the solution to the anharmonic oscillator, we
see the the period is close to 7.5. The result from Mathematica is
7.4163.
Numerical Integration
We talked about some of the standard methods for numerical
integration in one dimension. This is discussed in Section 11.1
of CSM. Additional material is available in Numerical Recipes
or in Abramowitz and Stegun. We discussed the rectangle rule,
trapezoid rule, and Simpson's rule.
We also discussed how to estimate the error for the rectangle rule
and for the trapzoid rule. In the next class, we will see how
Simpson's rule is much better.