f t+h ≈f t +hq t+h/2 - Department of Physics | Illinois State University

advertisement
Illinois State University
Department of Physics
Physics 112
Physics for Scientists and Engineers III
Computational Physics Laboratory 4: Damped Oscillator
Feynman-Newton Method for Solving First-Order Differential Equations
Introduction
In this unit you will apply your knowledge of Mathematica to solve Newton's Second Law for the
motion of an oscillator acted upon by a velocity-dependent drag or damping force. The drag is a force
Fdamp which is directed opposite from the direction of the motion and which has a magnitude
Fdamp = cv,
(1)
where c is the damping coefficient and v is the velocity of the oscillating mass. Newton's Second Law
for an oscillator of mass m acted upon by a linear restoring force with spring-constant k is
F  t  =ma  t  =m
d2 x
=−kx  t  −cv  t  ,
dt 2
(2)
and is a second-order differential equation. As in the third computational lab, Eq. (2) can be expressed
as two first-order differential equations,
dv F  t 
=
dt
m
(3)
dx
=v  t  .
dt
(4)
and
You can try to use the Euler method to solve this problem, but you will find that it is unreliable at
best. This problem is solved better by using an improvement to the Euler method known as the
Feynman-Newton Method or the half-step method. In this method the solution to a first-order
differential equation,
dx
=q ( t ) ,
dt
(5)
is obtained by using the value of the forcing function q(t) halfway between t and t + h, i.e. iterating
f  t+h  ≈f  t  +hq  t+h/2  .
(6)
This algorithm is known as the Feynman-Newton method or half-step method for obvious reasons.
Objectives
In this unit you will:
1. Use the Feynman-Newton algorithm to solve Newton's Second Law for the motion of an
oscillator with a velocity-dependent drag or damping force.
2. Compare the result to the Euler method and to the analytic solution.
3. Plot both x(t) as a function of t and v(x) versus x (phase space plot).
Assignment
1. Solve the problem for the damped oscillator by two methods:
a. Euler Method: Solve the damped harmonic oscillator with the Euler method. Use h = 0.25 s
and h = 1.0 s, and integrate from t = 0 to t = 25 s. Take k = 1 N/m, c = 0.1 kg/s and m = 1 kg,
and use initial conditions x(0) = 1 m and v(0) = 0 m/s. Hand in the source code.
Which time step provides more accurate results? Why?
b. Feynman-Newton Method: Modify your program to use the Feynman-Newton method and
solve the same problem. Use h = 0.25 s and h = 1.0 s, and integrate from t = 0 to t = 25 s.
Hand in the source code.
Which time step provides more accurate results? Why?
2. Compare with analytic solution: The exact solution,
x(t) = 1.00125 xo e -0.05t cos(0.0500209 - 0.998749t),
can be obtained analytically if you know some differential equations. This analytic solution is for
x(0) = xo and v(0) = 0 m/s and the above parameters. Compare both the Euler and FeynmanNewton numerical solutions for x(t) (using h = 0.25 s) to the analytic solution at various times.
Which numerical method best approximates the analytic solution? Choose a method to quantify
your discussion. Perhaps a plot of the differences between trajectories will be useful. Are the
results what you expected? Explain.
3. Phase space plot: Make a plot of your data from part 1b above with velocity v(t) on the ordinate
(y-axis) and the position x(t) on the abscissa (x-axis). The result is a picture of the trajectory of
the mass in “phase space”. From the plot, determine where the mass is when the v = 0 m/s. What
is its speed when x = 0 m? Where will the mass be and what will its speed be as t → ∞? (This is
called a “fixed point”). What happens to the initial energy of the mass (what is it?) as time
passes? Where does it go?
Appendix
Fig. 1 is a sample of the Mathematica code used to implement the Feynman-Newton algorithm.
Figure 1.
The same basic code written in Fortran 77 is shown in Fig. 2. This will run directly as Fortran 95 as
well, because Fortran 77 is a subset of Fortran 95. There really is not a lot of differences between the
codes.
Figure 2.
C
C
Initialize acceleration, position, and velocity.
C
Get velocity after half time-step (F-N method)
C
ACCEL = -(C1*XSTART + C2*VSTART)
XOLD = XSTART
VOLD = VSTART + H*ACCEL/2.
C
C
Loop for stepping in time
C
Note VOLD is half step ahead of XOLD
C
DO 10 J = 1,NUMPTS
XNEW = XOLD + H*VOLD
ACCEL = -(C1*XNEW + C2*VOLD)
VNEW = VOLD + H*ACCEL
TIMEX = TIME + H
TIMEV = TIMEX + H/2.
WRITE(10,'(5(E12.5,3X))') TIMEX,XNEW,TIMEV,VNEW,ACCEL
XOLD = XNEW
VOLD = VNEW
10 CONTINUE
Note that only the velocity is computed at the half-timestep, i.e. the Feynman-Newton method used to
solve Eq. (4). Eq. (5) computes a position based on the velocity from the previous half-timestep. Then
acceleration is computed with the same velocity and the position for the next time step. Thus, in the
loop, the new position is computed first, then the acceleration, then the new velocity. If you try to
compute ACCEL using XOLD instead of XNEW you might find that everything blows up! This is an
example of a numerical instability and is an example of how careful you must be in using numerical
methods to solve physics problems.
Strictly speaking, the position and velocity are calculated at different times, so I have accounted for that
in the sample above by saving times for each variable in the FORTRAN example. You could do the
same thing in Mathematica. Thus, the phase space plots are only approximate (since you should be
plotting x(t) and v(t) at the same t). However, for small h the difference is small.
Download