You are on page 1of 12

Physics with Mathematica Fall 2013 Exercise #1 27 Aug 2012

A Simple “Introductory” Exercise: Motion of a Harmonic Oscillator

In general, you should be able to work the daily exercise using what we covered on math-
ematica in class, but you will also usually need to find some things yourself using the
documentation in the program.

A simple harmonic oscillator is constructed from a mass m and a spring with stiffness con-
stant k. It moves in one dimension x(t) with velocity v(t) where

x(t) = A cos(ωt + φ)
and v(t) = ẋ(t) = −ωA sin(ωt + φ)
q
where ω = k/m. The kinetic energy of the mass is K = 12 mv 2 . At the initial time t = 0,
the position and velocity are given by

x0 = x(0) = A cos φ
and v0 = v(0) = −ωA sin φ

so that
s
v02
A = x20 +
ω2
v0
 
and φ = tan−1 −
ωx0

Plot the kinetic energy as a function of time, from t = 0 to t = 10 sec, for an oscillator with
m = 1.75 kg, k = 2 N/m, and which starts from x0 = 0.25 m with velocity v0 = 1.25 m/sec.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #2 3 Sep 2012
Plotting Orbits

Orbits in a gravitational field are described in plane polar coordinates (r, φ) as


r0
r(φ) =
1 +  cos φ
where r0 is a scale parameter and  is the eccentricity of the orbit. The orbit shape is named

“circle” for =0


“ellipse” for 0 <  < 1
“parabola” for =1
“hyperbola” for >1

Write a Mathematica notebook that does the following:

1. Defines a function r of some angle to express and arbitrary orbit

2. Derives expressions x = x(φ) = r cos φ and y = y(φ) = r sin φ

3. For one choice of value for r0 , and appropriate choices for , derive expressions for
the coordinate list {x, y} that describe a (a) circle, (b) ellipse, (c) parabola, and (d)
hyperbola.

4. Produces a single plot showing each of the four orbit shapes, using ParametricPlot. You
will have to use Show if you use more than one instance of ParametricPlot, in order to
get all four curves on just one plot. For the hyperbola, plot only the one branch that
extends to the same side of the focus (i.e. r = 0) as the parabola.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #3 10 Sep 2012
Projectile Motion and Range

A projectile is fired with initial speed v0 from the edge of a cliff, at an angle θ with respect
to the horizontal (x) direction. The cliff is a height y = h above the ground. The equations
describing the motion of the projectile are therefore, with (x, y) = (0, 0) being the edge of
the cliff,
1
x = v0 t cos θ and y = h + v0 t sin θ − gt2
2

Using g = 9.8 m/sec2 and choosing some appropriate value for v0 , make a parametric plot
of the trajectory, that is y versus x. Make it so that you can easily reproduce the plot for
different values of h and θ. Try different values of h and θ and convince yourself that the
trajectories look reasonable.

Then, solve the equation y(t) = 0 for the time when the projectile hits the ground. Use this
time to find the range x(t), and make a plot of the range versus either θ for a fixed h, or
versus h for a fixed θ. In fact, it would be most slick if you used Manipulate to allow the
fixed value to be easily changed.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #4 17 Sep 2012
Potential and Field from a Uniformly Charged Line Segment

The electrostatic potential from a charge distribution is given, in CGS units, by


Z
dq 0
V (x) =
|x − x0 |

where dq 0 = ρ(x0 )dV for a volume charge density ρ(x), dq 0 = σ(x0 )dA for a surface charge
density σ(x), and dq 0 = λ(x0 )ds for a line charge density λ(x). Given an electrostatic
potential function V (x), the electric field from that charge distribution is E(x) = −∇V (x).

Consider a straight line segment of uniformly distributed charge Q and length L, lying along
the x-axis and centered on the origin. The line charge density is then simply λ = Q/L. Find
the electrostatic potential along the z-axis, that is V (x) = V (0, 0, z). Express your result in
the simplest form that you can, perhaps using the Simplify function in Mathematica. Do
the same for (the z-component of) the electric field along the z-axis.

Test your results by considering the electric field in the limits z  L and z  L, in which
case you ought to be able to use your Physics II knowledge to figure out what you expect.
The best way to find these limits (I think) is to look for the appropriate series expansion in
terms of z. (Use the Documentation Center!) Note that the integral form of Gauss’ Law is
I
E · dA = 4πQencl

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #5 24 Sep 2012
Forced Damped Oscillations and “Resonance”

The exercise is to plot the motion of a forced, damped harmonic oscillator including the initial
conditions which shows the transient behavior. This is always avoided in classes because the
math is onerous. It’s a snap with mathematica, though, and the transient behavior can
be interesting to observe.

The equation of motion for the forced oscillator is

ẍ + 2β ẋ + ω02 x = A cos ωt

It is convenient to express the motion in terms of the natural period τ0 ≡ 2π/ω0 and the
driving period τ ≡ 2π/ω.

Solve this differential equation for the motion x(t) and plot for 0 ≤ t ≤ 10, using β = 0.1,
and natural period τ0 = 1, subject to the initial conditions x(0) = ẋ(0) = 0. Try plotting it
first for a driving period τ = 2 and amplitude A = 1. Then, try it for some other choices
of these parameters. Remember to keep β < ω0 if you want to have an oscillating transient,
but that is not necessary.

Next, use manipulate to study the behavior of the forced oscillator. Probably the most
dramatic parameter to manipulate is τ , and let it span over τ0 so that you can observe
resonance.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #6 1 Oct 2012
The Humped Potential Well

An object of mass m moves in one dimension x according to Newton’s Second Law F = mẍ
with a force F (x) = ax2 − bx. Assume that a and b are positive constants.

Numerically solve for x(t) with initial conditions ẋ(0) = 0 and x(0) = x0 , and plot the results.
Solve and plot for 0 ≤ t ≤ tMax where tMax is large enough for you to see the behavior as
t → ∞. Let x0 takes on each of three values of your choosing, but with the constraints

1. |x0 |  b/2a

2. x0 close to −b/2a but a little larger (i.e. closer to zero)

3. x0 close to −b/2a but a little smaller (i.e. farther from zero)

You’ll need to put in numerical values for everything in order to solve Newton’s Second Law
numerically. You are welcome to choose whatever values you want for a, b, and m, but you
may want to play around with them a little to make the plots look nice.

What is so special about x = −b/2a? You might try solving and plotting
Rx
for x0 = −b/2a to
get a big hint. You might also plot the potential energy U (x) = − 0 F (u)du for a bigger
hint. The integral is simple, but you can ask mathematica to do it for you; no need for a
numerical integral here, though.

Send the grader an email with your notebook as an attachment. Note


that at this point, you should be getting into the habit of putting
appropriate comments into your code.
Physics with Mathematica Fall 2013 Exercise #7 8 Oct 2012
Basic Matrix Manipulation

This exercise uses mathematica for some standard calculations with a Hermitian matrix.
We will work with the spin-one y-matrix from quantum mechanics:
 
0 −i 0
1 
M = √  i 0 −i 

2 0 i 0

Define this matrix in mathematica and carry out the following operations. Note that, for
a matrix A, the Hermitian transpose is designated as A† .

1. Show that M is Hermitian, that is M − M† = 0. You might also, or instead, try using
the function HermitianMatrixQ.

2. Find the eigenvalues and eigenvectors of M. Extract the eigenvectors v1 , v2 , and v3 .

3. The eigenvectors are not normalized. Find the normalization constants for each of the
three eigenvectors vi by taking the square root of vi† vi .

4. Form a matrix U using the normalized eigenvectors for columns. Show that U† U = 1,
that is the identity matrix.

5. Calculate the matrix U† MU. Show that it is diagonal, with the diagonal elements equal
to the eigenvalues of M.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #8 22 Oct 2012
Elementary Data Analysis: Gas Mileage in Winter vs Summer

Download the file MPG.dat from the course website. This is a two-column data file. The
first column is the day since 1 July 2008, and the second is the gas mileage (in miles per
gallon) of a car, a routinely maintained 1994 Honda Accord, since the last time the tank
was filled. The science goal of this exercise is for you to observe the change in gas mileage
between summer and winter.

Find the average gas mileage and its standard deviation. You might want to use the Docu-
mentation Center to identify the built-in functions that give you these answers.

Make a plot of the gas mileage as a function of day. That is, plot a set of points with the
first column as the x-axis and the second column as the y-axis. Set the axis limits from zero
to 2000 for the days, and 20 to 40 for the mileage. Label the axes “Day since July 1, 2008”
and “MPG”.

Now make two separate histograms of the gas mileage, each for certain periods of time. One
histogram should be for the January and February months, and other for July and August.
Find the average gas mileage and the standard deviation for each of these two sets of data,
and make sure those answers look reasonable based on your histograms.

Note: There are few ways to take the first column and figure out what month it implies.
The simplest thing to do is to find the remainder when dividing by 365 - the Mod function -
in which case a number less than 62 means July or August, or between 184 and 263, that is,
January or February. A nicer way, which takes into account leap years, is to use the DatePlus
function and work with the actual month as determined by Mathematica.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #9 29 Oct 2012
137
Fitting Data to a Curve: The Decay of Cs

This exercise is to fit some data for radioactive decay as a function of time, including a
constant background term. The number of counts −∆N > 0 detected in time ∆t is called
the decay rate R = −∆N/∆t ≈ −dN/dt. Quantum mechanics tells us that R is proportional
to N , the number of radioactive nuclei present at time t. That is dN/dt = −λN for some
positive constant λ = 1/τ , where τ is called the “lifetime” or “mean life.” Therefore

N (t) = N0 e−λt and R = λN0 e−t/τ = λN0 2−t/t1/2

where, for convenience, we often use the “half life” t1/2 instead of the lifetime.

Download the file Cs137.dat. It has two columns, the first is time (in 20-second intervals) and
the second is the number of detected decays during that time interval. The data was taken
as part of an undergraduate physics laboratory experiment, where samples of radioactive,
but very long lived, 137 Cs were used to separate out the radioactive daughter 137m Ba. This
relatively short lived isomeric state in turn decays to the ground state by emitting a gamma
ray. These gamma rays were detected by a Geiger counter as a function of time. You’ll see
from the data that a constant background level persists after the 137m Ba has decayed away.

The goal of this exercise is for you to fit an appropriate functional form to this data and to
determine the half life of the 137m Ba isomer. It should be easy enough for you to find the
accepted value for the half life on the web, and compare it to your result.

Your notebook should include the following:

• Importing the file Cs137.dat.

• Defining your fit function and fitting the data to it.

• A plot of the data as a function of time, with your fit function superimposed on it.

• A plot of the difference between your fit function and the data as a function of time.

An appropriate time unit to use for the half life is minutes. I suggest you operate on the
data file so that the 20-second time bins are in fact labeled as thirds of minutes.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #10 5 Nov 2012
Determining π from a Monte Carlo Calculation

This conceptually simple exercise will give you some practice in numerical calculations in
Mathematica, including some work with random numbers.

Your goal is determine π from a Monte Carlo simulation. This is basically a cheap way to
calculate an integral numerically, using random numbers. The technique is akin to throwing
dice, hence the name. (If you’ve never heard of Monte Carlo or the principality of Monaco,
you should look it up!)

Consider a square with side length two, and a circle of radius one, both centered at the
origin. The area of the square is four and the area of the circle is π. So, you can write that
area of circle
π =4×
area of square
Instead of calculating those areas analytically, though, you’ll do it by “throwing dice.”

Use the Documentation Center to learn how to generate an array of random number pairs
(x, y), of arbitrary length nPts, where both x and y are uniformly distributed between −1
and 1. You should plot the points you generate and confirm that they uniformly fill the
square. Maybe you want to superimpose on top of that a plot of the unit circle. Now select
the points for which x2 + y 2 ≤ 1. You should probably plot these as well, and make sure that
they uniformly populate the unit circle. Use nPts and the number of points you selected to
calculate a value of π, and compare it to the precise value up to some number of significant
figures. How large does nPts need to be in order to get a decent value for π?

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #11 12 Nov 2012
Animation of a Mass on a Spring

Make an animation of a square block, connected to a spring, undergoing simple harmonic


motion. The spring is connected to a fixed point at x = 0, compressing and expanding with
the block. Draw the block with the Polygon graphic primitive function of Mathamatica.
You can draw the spring as a sine function with some number of wavelengths. You should
end up with something like the following, shown at some intermediate time:

You’ll have to make the center of the block, as well as the right endpoint and wavelength of
the sine function, depend on time. Describe the motion of the block with something like

x(t) = 0.5 + 2.5(1 + cos 2πt)

which is what I used for the picture above, but by now you should be able to set this all
up with parameters that you can vary. (If you’d like to do this by solving some differential
equation that includes damping, or anharmonic terms, or. . . , be my guest!) Use the correct
AspectRatio to make sure the block is drawn as a square.

Send the grader an email with your notebook as an attachment.


Physics with Mathematica Fall 2013 Exercise #12 19 Nov 2012
Plotting the Electric Potential and Electric Field from Two Point Charges

This is really an exercise in some advanced plotting techniques.

Consider two charges, one positive and one negative, at different points in the (x, y) plane.
Calculate the electric potential V (x, y) from these charges, and make a 3D “surface” plot of
the potential over some region of the plane. Choose whatever values you like for the charges,
their positions, and the limits of your plot.

Calculate the electric field E(x, y) = −∇V (x, y) from your potential. Then make a single
picture of some portion of the (x, y) plane that includes the following:

• A filled-in blue circle showing the position of the positive charge, and a filled-in red
circle showing the position of the negative charge.

• A contour plot of the potential. Make the contour lines black, and put fixed labels on
them. (You might want to notice that “tooltip” information is available; just move
your cursor over a contour to see the value.)

• Plot the electric field lines in green.

You’ll need to spend some time in the Documentation Center in order to learn how to make
these various specific features of the picture.

Send the grader an email with your notebook as an attachment.

You might also like