You are on page 1of 21

Computation in Classical Mechanics

J. E. Hasbun

Department of Physics
University of West Georgia

Scientific advances create the need to become computationally adept to


tackling problems of increasing complexity. The use of computers in
attaining solutions to many of science’s difficult problems is inevitable.
Therefore, educators face the challenge to infuse the undergraduate
curriculum with computational approaches that will enhance students’
abilities and prepare them to meet the world’s newer generation of
problems. Computational physics courses are becoming part of the
undergraduate physics landscape and learned skills need to be honed and
practiced. A reasonable ground to do so is the standard traditional upper
level physics courses. I have thus developed a classical mechanics
textbook1 that employs computational techniques. The idea is to make
use of numerical approaches to enhance understanding and, in several
cases, allow the exploration and incorporation of the “what if
environment” that is possible through computer algorithms. The
textbook uses Matlab because of its simplicity, popularity, and the
swiftness with which students become proficient in it. The example
code, in the form of Matlab scripts, is provided not to detract students
from learning the underlying physics. Students are expected to be able to
modify the code as needed. Efforts are under way to build OSP2 Java
programs that will perform the same tasks as the scripts. Selected
examples that employ computational methods will be presented.
1 To be published, Jones and Bartlett Publishers.
2 Open Source Physics: http://www.opensourcephysics.org/.
Table of Contents

Chapter 1 Review of Newton's Laws


Euler’s method (computation)
Chapter 2 Application of Newton's 2nd Law of Motion in One
Dimension
Chapter 3 Harmonic Motion in One Dimension
Chapter 4 Examples of Harmonic Motion
Interacting Spring-Mass System (Computation)
Chapter 5 Vectors and Differential Calculus
Chapter 6 Motion Beyond One Dimension
Charged particle in 3d under both E\&M fields
(computation)
Chapter 7 Systems of Coordinates
Foucault pendulum (computation)
Chapter 8 Central Forces
Chapter 9 Gravitation
Binary System (simulation)
Chapter 10 Rutherford Scattering
Rutherford Scattering (simulation)
Chapter 11 Systems of Particles
Chapter 12 Motion of Rigid Bodies
Symmetric Top (simulation)
Chapter 13 Lagrangian Dynamics
Double Pendulum (simulation)
Principle of Least Action (simulation)

Chapter 1 Highlights
Why we need computational physics? We can go beyond solvable problems. We
can get more insight. We can explore situations beyond classroom examples.

Start with the iterative Euler method.


Chapter 1 Highlights

Why we need computational physics? We can go beyond solvable problems. We


can get more insight. We can explore situations beyond classroom examples.

If we know the acceleration of an object,

∫ dv = ∫ a dt
If the acceleration is constant, an object’s velocity is
1 2
v(t ) = v0 + at ⇒ ∫ dx = ∫ v(t )dt ⇒ x(t ) = x0 + v0 t +
2
at

However, if the acceleration is not constant, say a mass at the end of a spring,

Fs = −k x(t ) d 2 x dv
a(t ) = −k x(t ) / m = 2 =
dt dt
The analytic solution is done in a later chapter. Let’s look at a numerical solution.
MATLAB code is provided. Students are encouraged to run it and explore it.
•The Euler Method to solve a 2nd order DE: convert it to two 2nd order DE’s
dx dv
= v(t , x) and = a (t , v) So that we do,
dt dt
vi +1 = vi + ai ∆t , xi +1 = xi + vi +1 ∆t to be solved on [t0 , t f ] with

ti +1 = ti + ∆t , ai = −k xi m . For N steps ∆t = ( t f − t0 ) N

Given initial conditions: x0 , v0


First example, by calculator (reproduced by a general force MATLAB code): let

k = 1000 N / m, m = 5kg , x0 = 0.1m, v0 = 0.0m / s on time interval [0,1s ]

for N = 10 so that ∆t = 0.1


•Create a table of the calculations

i ti = i ∆t vi +1 = vi + ai ∆t xi +1 = xi + vi +1 ∆t ai = −200 xi m

0 0.0 0.0 0.1 -20


1 0.1 -2.0 -0.1 20
2 0.2 0.0 -0.1 20
3 0.3 2.0 0.1 -20
4 0.4 0.0 0.1 -20
5 0.5 -2.0 -0.1 20
6 0.6 0.0 -0.1 20
7 0.7 2.0 0.1 -20
8 0.8 0.0 0.1 -20
9 0.9 -2.0 -0.1 20
10 1.0 0.0 -0.1 20

•Can create a plot of this rough calculation


Matlab Code for the above example

%ho1.m
%Calculation of position, velocity, and acceleration for a harmonic
%oscillator versus time. The equations of motion are used for small time intervals
clear;
%NPTS=100;TMAX=1.0;%example Maximum number of points and maximum time
TTL=input(' Enter the title name TTL:','s');%string input
NPTS=input(' Enter the number calculation steps desired NPTS: ');
TMAX=input(' Enter the run time TMAX: ');
NT=NPTS/10;%to print only every NT steps
%K=1000;M=5.0;C=0.0;E=0.0;W=0.0;x0=0.1;v0=0.0;% example Parameters
K=input(' Enter the Spring contant K: ');
M=input(' Enter the bob mass M: ');
C=input(' Enter the damping coefficient C: ');
E=input(' Enter the magnitude of the driving force E: ');
W=input(' Enter the driving force frequency W: ');
x0=input(' Enter the initial position x0: ');% Initial Conditions
v0=input(' Enter the initial velocity v0: ');% Initial Conditions
t0=0.0;% start at time t=0
dt=TMAX/NPTS;%time step size
fprintf(' Time step used dt=TMAX/NPTS=%7.4f\n',dt);%the time step being used
F=-K*x0-C*v0+E*sin(W*t0); % initial force
a0=F/M;% initial acceleration
fprintf(' t x v a\n');%output column labels
v(1)=v0;
x(1)=x0;
a(1)=a0;
t(1)=t0;
fprintf('%7.4f %7.4f %7.4f %7.4f\n',t(1),x(1),v(1),a(1));%print initial values
for i=1:NPTS
v(i+1)=v(i)+a(i)*dt; %new velocity
x(i+1)=x(i)+v(i+1)*dt; %new position
t(i+1)=t(i)+dt; %new time
F=-K*x(i+1)-C*v(i+1)+E*sin(W*t(i+1)); %new force
a(i+1)=F/M; %new acceleration
% print only every NT steps
if(mod(i,NT)==0)
fprintf('%7.4f %7.4f %7.4f %7.4f\n',t(i+1),x(i+1),v(i+1),a(i+1));
end;
end;

ho1.m continued on next page


ho1.m continued from previous page

subplot(3,1,1)
plot(t,x,'k-');
ylabel('x(t) (m)','FontSize',14);
h=legend('position vs time'); set(h,'FontSize',14);
title(TTL,'FontSize',14);
subplot(3,1,2)
plot(t,v,'b-');
ylabel('v(t) (m/s)','FontSize',14);
h=legend('velocity vs time'); set(h,'FontSize',14)
subplot(3,1,3)
plot(t,a,'r-');
ylabel('a(t) (m/s^2)','FontSize',14);
xlabel('time (sec)','FontSize',14);
h=legend('acceleration vs time'); set(h,'FontSize',14)

•We also need to be able to visualize analytical solutions – so use small MATLAB
scripts provided or modify available ones
•Harmonic Motion example: Interacting Spring-Mass System (Computation)

Interaction mass-
spring system
a)with walls, and b)
without walls

d 2 x1 d 2 x2
m1 2 = − k1 x1 − k0 ( x1 − x2 ) and m2 2
= − k2 x2 − k0 ( x2 − x1 )
dt dt
•Case 1: No Walls - Single Mode k1 = k2 = 0 The analytic solution is:
m2 m1
x1 (t ) = xcm (t ) − xcm 0 − xr (t ) x2 (t ) = xcm (t ) − xcm 0 + xr (t )
m1 + m2 m1 + m2

xr = A sin ω t + B cos ω t , ω A = vr 0 = v20 − v10 , B = xr 0 = x20 − x10

m x + m2 x2 m1v1 + m2 v2 m1v10 + m2 v20


xcm (t ) − xcm 0 = 1 1 = vcm t vcm = =
m1 + m2 m1 + m2 m1 + m2
•Can create a plot of this calculation inter_spr1.html

The coupled mass-


spring system
without walls with
a single mode of
vibrations

•Case2: Full System - Bimodal m1 = m2 = m, k1 = k2 = k ≠ k0

Write the equations in the matrix form x = − k x − k0 M x


m 
⎛m 0 ⎞ ⎛ x1 ⎞ ⎛k 0⎞ ⎛ 1 −1⎞
where m≡⎜ ⎟ x≡⎜ ⎟ k ≡⎜ M ≡⎜
⎝ ⎠ ⎟ ⎟
0 m ⎝ x2 ⎠ ⎝ 0 k ⎠ ⎝ −1 1 ⎠
Solve using eigenvalue-eigenvector method, get two modes
x1 (t ) = x10 cos ω t cos ωm t + x20 sin ω t sin ωm t
x2 (t ) = x10 sin ω t sin ωm t + x20 cos ω t cos ωm t
Average ω = (ω + ω ) / 2 Modulation
frequency
1 2
frequency ωm = (ω2 − ω1 ) / 2
•Can create a plot of this calculation inter_spr2.html

The solution of the


full coupled
spring-mass
bimodal system
• Three Dimensional Motion of a charged Particle in an Electromagnetic
Field (Computation) - This follows the two dimensional analytic solutions
of the charge in Electric, magnetic, and joint E& B fields
We have
K K K K K
F = qv × B + qE = ma or

d 2x d2y d 2z
= q (v y Bz − vz By + Ex ) / m, = q (vz Bx − vx Bz + E y ) / m, = q(vx By − v y Bx + Ez ) / m
dt 2 dt 2 dt 2
In MATLAB write these as

x → r (1), x → r (2); y → r (3), y → r (4); z → r (5), z → r (6)


Obtain six 1st order equations given by
dr (1) dr (2)
= r (2), = q [ r (4) B (3) − r (6) B (2) + E (1) ] / m
dt dt
dr (3) dr (4)
= r (4), = q [ r (6) B (1) − r (2) B (3) + E (2) ] / m
dt dt

dr (5) dr (6)
= r (6), = q [ r (2) B(2) − r (4) B (1) + E (3) ] / m
dt dt

where we have the field arrays E = ( E x , E y , E z ) = E (1, 2,3), B = ( Bx , By , Bz ) = B (1, 2,3)


−8 −9 −9 −8 −9 −8
Field values example: E = [0.5 × 10 ,1 × 10 , -3 × 10 ], B = [1× 10 , -1× 10 ,5.13 × 10 ]

• see
A charged particle cycloid3d.html
moving in the presence
of a three dimensional
electromagnetic field
Systems of Coordinates - Foucault pendulum (computation)

a) The Foucault
pendulum and b)
the forces on it.

K K K K K K K K
r ′ + 2ω × r ′ + ω × (ω × r ′ )
S-frame (Earth’s center) acceleration: a = − g kˆ ′ + T / m = 
K K K
Look at x-y plane motion, and ignore ω × (ω × r ′ ) , but keep the Coriolis term, and
K K Tx′ = −T sin α = −T cos β = −T x ′ / L
T = Tx iˆ′ + Ty ˆj ′, r ′ = x ′ iˆ′ + y ′ ˆj ′,
Ty′ = −T sin β = −T cos α = −T y ′ / L
x ′ = 2 y ′ω0 sin θ − g x ′ / L

get ω0 = 7.272 × 10−5 rad / s
y ′ = −2 x ′ω0 sin θ − g y ′ / L
 where for Earth

Solve and get: x ′(t ) = x0′ cos ω1t cos ω2 t + y0′ sin ω1t cos ω2 t
with
y ′(t ) = − x0′ sin ω1t cos ω2 t + y0′ cos ω1t cos ω2 t

ω f = g / L ← Pendulum frequency ω2 ≡ ω12 + ω f 2


ω1 = ω0 sin θ ← Precessional frequency θ ← Latitude angle

Equations (7.8.9) for a


Foucault pendulum with a
This is for a
24 hour period Foucault
pendulum with a
swinging period
of one hour
(very long!)

See
Foucault.html
Gravitation: Binary Mass
System Simulation
Center of mass
K K m K
r1 = rcm − 2 r of a binary mass
m system
K K m K
r2 = rcm + 1 r
m
Can write an equation for each mass
K K K K
d 2 r1 Gm1 m2 r12 d 2 r2 Gm1 m2 r21 K K K K K
m1 2 = − 3
, m2 2 = − r ≡ r21 = −r12 = r2 − r1
dt r12 dt r213
But can also use Center of Mass - Relative Coordinate Method
K K 1 1 1
⎛ cm ⎞ ⎛ 1
r m / m m / m ⎞ ⎛ 1 ⎞ and convert to an equation
r → = +
⎜ K ⎟=⎜ µ m1 m2
2
⎟⎜ K ⎟
⎝ r ⎠ ⎝ −1 1 ⎠⎝ r2 ⎠ for the reduced mass
K 2 K whose L2µ 1
d r Gm m r r=−
µ 2 = − 13 2
( )
solution we
µ K µ 1 − ⎡u0 L2µ / µ K µ ⎤ cos θ
dt r know ⎣ ⎦
v2 r 2 1 ⎛ 1+ e ⎞
or r= = rmin ⎜ ⎟
Then get r1 and
G (m1 + m2 ) ⎛ u0 v 2 r 2 ⎞ ⎝ 1 + e cos θ ⎠ r2. Example
⎜1 + cos θ ⎟ follows:
⎝ G ( m1 + m 2 ) ⎠

Using
astronomical
Binary system units
simulation using
analytic formulas see
binary1.html
and
binary1.avi
Rutherford Scattering (simulation)

Alpha particle
qtarget = Z t qe with impact
parameter
qprojectile = Z p qe directed at a
target
Projectile
d kqe2 Z t Z p equation of
m p (vx iˆ + v y ˆj ) = ( x iˆ + y ˆj ) motion
( )
3/ 2
dt x2 + y2 with a
fixed target
d ⎡ kqe2τ 2 ⎤ K ( x iˆ + y ˆj )
(vx iˆ + v y ˆj ) = ⎢ take ab = 1 fm
Use dimensionless units: 3 ⎥
( )
3/ 2
dt ⎣ mα ab ⎦ m x 2 + y 2 K = Z Au Zα
and let
kqe2τ 2 mα ab3 4(1.66 × 10−27 kg )(10−15 m)3 m =1
≡1⇒τ = = = 1.695 × 10−22 s
mα ab3 kqe2 Nm 2
(9 × 109 2 )(1.602 × 10−19 C ) 2
C
Speed unit: vb = ab τ = 1 × 10 m 1.695 × 10 s = 5.898 × 10 m / s = 0.01965c
−15 −22 6

Solve these dx dvx Kx dy dv y Ky


= vx , = ; = vy , =
numerically
( ) ( )
3/ 2 3/ 2
dt dt m x2 + y2 dt dt m x2 + y2

rmin = min ( x ( t )2 + y ( t )2 )

Numerical
simulation of a
See
projectile alpha
particle onto a gold ruther.html
target and
ruther.avi
.
Motion of Rigid Bodies – Symmetric Top (simulation)

Using
Eulerian Spinning symmetric top with its
angles symmetry axis (), which is its
spin axis as well as its principal
φ ,θ ,ψ axis of symmetry, at angle from
the fixed axis
K K
K ⎛ dL ⎞ ⎛ dL ⎞ K K
τ =⎜ ⎟ =⎜ ⎟ + ω ′′ × L = mg A sin θ iˆ′′
⎝ dt ⎠ fixed ⎝ dt ⎠ rot
K K
L = Iθiˆ′′ + I ϕ sin θ ˆj ′′ + I s ωs kˆ ′′, ω ′′ = θ iˆ′′ + ϕ sin θ ˆj ′′ + ϕ cos θ kˆ ′′
I 3 (ϕ cos θ + ψ ) ≡ I s ωs
or

mg A sin θ = Iθ + I s ωsϕ sin θ − I ϕ 2 cos θ sin θ solve numerically for

φ ( t ) , θ ( t ) ,ψ ( t )
d
0=I (ϕ sin θ ) − I s ωsθ + Iθϕ
  cos θ
dt
0 = I s ω s
(a) (b)

See
top.html
and
top.avi
(c)

spinning fixed point symmetric


top a) Numerical solution, b)
Plot of the energy and the
effective potential, and c) a
snapshot of the simulated
motion of the top's total angular
momentum as well as the body
angular momentum vs time
LAGRANGIAN DYNAMICS – Double Pendulum (simulation)

Double Pendulum
Coordinates
x1 = L1 sin θ1 x2 = x1 + L2 sin θ 2
y1 = L1 cos θ1 y2 = y1 + L2 cos θ 2

kinetic, potential energies

T=
1
2
( ) 1
( )
m1 x12 + y12 + m2 x22 + y 22 , V = m1 gL2 + m1 gh1 + m2 g ( h1 + h2 )
2

1 1
Lagrangian L = T −V = m1 L12θ12 + m2 ⎡⎣ L12θ12 + L22θ22 + 2 L1 L2θ1θ2 cos (θ1 − θ 2 ) ⎤⎦
2 2
− m1 gL2 − ( m1 + m2 ) gL1 (1 − cos θ1 ) − m2 gL2 (1 − cos θ 2 ) .
Lagrange’s
equations ( m1 + m2 ) L1θ1 + m2 L2θ2 cos (θ1 − θ2 ) = −m2 L2θ22 sin (θ1 − θ 2 ) − ( m1 + m2 ) g sin θ1
• solve m2 L2θ2 + m2 L1θ1 cos (θ1 − θ 2 ) = m2 L1θ12 sin (θ1 − θ 2 ) − m2 g sin θ 2
numerically

See
doublep.html
and
doublep.avi

The double pendulum a) Eulerian angles plotted versus time


(upper figure) and versus each other (lower figure) b)
simulation of the pendulum for the initial conditions shown.
LAGRANGIAN DYNAMICS – Principle of Least Action (simulation)

Hamilton’s principle
Three possible paths
in the evolution t2
process of the action I = δ ∫ Ldt = 0
integral t2 t1
S ≡ ∫ Ldt
t1

Hamilton’s principle: the motion followed by a mechanical system as it moves from


a starting point to a final point within a given time will be the motion that provides an
extremum for the time integral of the Lagrangian.

Example – case of a particle in free fall, we have the Lagrangian and the action:
tf tf
1 2 ⎛1 ⎞
L = T − V = mv y − mgy
2 t
∫ t ⎝

S = Ldt = ⎜ mv 2 − mgy ⎟ dt
2 ⎠
0 0

Numerically, make the approximation:


1 ⎛ y − yk ⎞
2
tf N −1 with Lk ≡ L ( tk ) ≈ m ⎜ k +1 ⎟ − mgyk

S = Ldt ≈ ∆t Lk ∑ 2 ⎝ ∆t ⎠
y f − y0 ( )
t0 k =1 and the initial guess yk = y0 + ( t k − t0 )
t f − t0 ( )
Modify the guess randomly, accept steps that lead to s decrease in dS = S n , N −1 − S n −1, N −1
until dS is small. Compare numerical results against the exact solution
1 2
y = y0 + v0 t − gt
2

See
Simulation of Hamilton's least_action.html
least action principle for and
the case of the motion of least_action.avi
a single particle free
falling near Earth's
surface, in one dimension
Other Highlights

•Harmonic oscillator (undamped, damped, and forced)

•Projectile Motion (analytic and numerical)

•The pendulum (small, and large angles)

•Central Forces
-Planetary Motion (analytic, numerical, and simulations) and comparison
with data

•Eulerian Angle Frame Rotation (visualization)

•More on Rutherford Scattering


--Comparison with the 1913 Geiger Marsden Data for Silver and Gold
Conclusion

•A junior level mechanics textbook has been developed that


incorporated computational physics: “Intermediate Classical
Mechanics with MATLAB applications.”

•The text makes use of the valuable traditional analytic approach


in pedagogy. It further incorporates computational techniques to
help students visualize, explore, and gain insight to problems
beyond idealized situations.

•Some programming background is expected and most


physics/engineering majors have had programming experience
by their junior year.

•The emphasis is placed on understanding. The analytic


approach is supported and complemented by the computational
approach.

•Java applications analogue to the MATLAB scripts are


available (under development) see below. They use the Open
Source Physics (OSP) library of W. Christian and co-workers.
http://www.westga.edu/~jhasbun/osp/osp.htm
http://www.opensourcephysics.org/

•Comments are welcome. Please contact J. E. Hasbun


jhasbun@westga.edu
OPEN SOURCE PHYSICS (OSP) JAVA APPLICATIONS

ho1app

inter_spr1App
inter_spr2App

cycloid3dApp
foucaultApp

binary1App
rutherApp

topApp
doublepApp

least_actionApp

You might also like