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 mathematica 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 constant 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 + φ) where ω = k/m. The kinetic energy of the mass is K = 1 2 mv2. At the initial time t = 0, the position and velocity are given by x 0 = x(0) = A cos φ and v 0 = v(0) = ωa sin φ so that A = x 2 0 + v2 0 ω ( 2 and φ = tan 1 v ) 0 ωx 0 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 x 0 = 0.25 m with velocity v 0 = 1.25 m/sec.
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 r(φ) = r 0 1 + ɛ cos φ where r 0 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 r 0, 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.
Physics with Mathematica Fall 2013 Exercise #3 10 Sep 2012 Projectile Motion and Range A projectile is fired with initial speed v 0 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, x = v 0 t cos θ and y = h + v 0 t sin θ 1 2 gt2 Using g = 9.8 m/sec 2 and choosing some appropriate value for v 0, 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.
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 V (x) = dq x x where dq = ρ(x )dv for a volume charge density ρ(x), dq = σ(x )da for a surface charge density σ(x), and dq = λ(x )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 E da = 4πQ encl
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βẋ + ω 2 0x = 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.
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) = ax 2 bx. Assume that a and b are positive constants. Numerically solve for x(t) with initial conditions ẋ(0) = 0 and x(0) = x 0, and plot the results. Solve and plot for 0 t t Max where t Max is large enough for you to see the behavior as t. Let x 0 takes on each of three values of your choosing, but with the constraints 1. x 0 b/2a 2. x 0 close to b/2a but a little larger (i.e. closer to zero) 3. x 0 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 for x 0 = b/2a to get a big hint. You might also plot the potential energy U(x) = 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. 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: M = 1 2 0 i 0 i 0 i 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 v 1, v 2, and v 3. 3. The eigenvectors are not normalized. Find the normalization constants for each of the three eigenvectors v i by taking the square root of v i v i. 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.
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 Documentation 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.
Physics with Mathematica Fall 2013 Exercise #9 29 Oct 2012 Fitting Data to a Curve: The Decay of 137 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) = N 0 e λt and R = λn 0 e t/τ = λn 0 2 t/t 1/2 where, for convenience, we often use the half life t 1/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.
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 π = 4 area of circle 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 x 2 +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 π?
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.
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.