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 sciences 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 worlds 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/.

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

## Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13

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 objects velocity is

v(t ) = v0 + at

dx = v(t )dt
Fs = k x(t )

x(t ) = x0 + v0 t +

1 2 at 2

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

d 2 x dv a(t ) = k x(t ) / m = 2 = dt dt

The analytic solution is done in a later chapter. Lets 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 DEs

dx = v(t , x) dt

and

dv = a (t , v) dt

So that we do,

vi +1 = vi + ai t ,
ti +1 = ti + t ,

xi +1 = xi + vi +1 t ai = k xi m .

to be solved on [t0 , t f ]

with

For N steps

t = ( t f t0 ) N

x0 , v0
on time interval

for

[0,1s ]

N = 10

so that

t = 0.1

## Create a table of the calculations i 0 1 2 3 4 5 6 7 8 9 10

ti = i t

vi +1 = vi + ai t xi +1 = xi + vi +1 t ai = 200 xi m
0.0 -2.0 0.0 2.0 0.0 -2.0 0.0 2.0 0.0 -2.0 0.0 0.1 -0.1 -0.1 0.1 0.1 -0.1 -0.1 0.1 0.1 -0.1 -0.1 -20 20 20 -20 -20 20 20 -20 -20 20 20

0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

## 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 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 massspring system a)with walls, and b) without walls

d 2 x1 m1 2 = k1 x1 k0 ( x1 x2 ) dt
Case 1: No Walls - Single Mode

and

d 2 x2 m2 = k2 x2 k0 ( x2 x1 ) 2 dt
The analytic solution is:

k1 = k2 = 0

x1 (t ) = xcm (t ) xcm 0

m2 xr (t ) m1 + m2

x2 (t ) = xcm (t ) xcm 0

m1 + xr (t ) m1 + m2

xr = A sin t + B cos t ,

A = vr 0 = v20 v10 ,
vcm =

B = xr 0 = x20 x10

xcm (t ) xcm 0

m x + m2 x2 = 1 1 = vcm t m1 + m2

## Can create a plot of this calculation

inter_spr1.html

The coupled massspring system without walls with a single mode of vibrations

m1 = m2 = m,
x1 x x2

k1 = k2 = k k0

## Write the equations in the matrix form where

m 0 m 0 m

m x = k x k0 M x
k 0 k k 0 1 1 M 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 1 2 frequency Modulation m = (2 1 ) / 2 frequency 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 or
d2y = q (vz Bx vx Bz + E y ) / m, dt 2 d 2z = q(vx By v y Bx + Ez ) / m dt 2

F = qv B + qE = ma
d 2x = q (v y Bz vz By + Ex ) / m, dt 2

x r (1),

r (2); x

y r (3),

r (4); y

r (6) z r (5), z

## Obtain six 1st order equations given by

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

dr (3) = r (4), dt

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

dr (5) = r (6), dt

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

E = ( E x , E y , E z ) = E (1, 2,3),

## where we have the field arrays

B = ( Bx , By , Bz ) = B (1, 2,3)

## A charged particle moving in the presence of a three dimensional electromagnetic field

see cycloid3d.html

## Systems of Coordinates - Foucault pendulum (computation)

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

## + T / m = + ( r ) S-frame (Earths center) acceleration: a = g k r + 2 r

Look at x-y plane motion, and ignore ( r ) , but keep the Coriolis term, and

+ Ty j , T = Tx i j , r = x i + y
get

0 sin g x / L x = 2 y 0 sin g y / L y = 2 x

## cos 1t cos 2 t + y0 sin 1t cos 2 t Solve and get: x (t ) = x0

f = g / L Pendulum frequency 1 = 0 sin
Precessional frequency

with

2 12 + f 2

Latitude angle

## Equations (7.8.9) for a Foucault pendulum with a 24 hour period

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

## Gravitation: Binary Mass System Simulation

m r1 = rcm 2 r m m r2 = rcm + 1 r m

## d 2 r1 Gm1 m2 r12 d 2 r2 Gm1 m2 r21 m1 2 = , m2 2 = 3 3 dt r12 dt r21

r r21 = r12 = r2 r1

But can also use Center of Mass - Relative Coordinate Method 1 1 1 = + r / / r m m m m cm 1 1 and convert to an equation 2 m1 m2 = 1 r2 for the reduced mass r 1

Gm m r d r 2 = 13 2 dt r
2

## whose solution we know

r=

L2

K 1 u0 L2 / K cos
Then get r1 and r2. Example follows:

or

## Rutherford Scattering (simulation)

qtarget = Z t qe qprojectile = Z p qe

## Alpha particle with impact parameter directed at a target

kqe2 Z t Z p d + vy + y m p (v x i j) = j) (x i 3/ 2 2 2 dt x +y

## Use dimensionless units:

kqe2 2 1 = 3 m ab

and let

+ y kqe2 2 K ( x i j) d (v x i + v y j ) = 3 3/ 2 dt m ab m x 2 + y 2

take ab = 1 fm

K = Z Au Z

3 m ab = kqe2

m =1

## Solve these numerically

dx = vx , dt

dvx Kx = dt m x2 + y2

3/ 2

dy = vy , dt

dv y dt

Ky m x2 + y2

3/ 2

rmin = min

x ( t )2 + y ( t )2

## Motion of Rigid Bodies Symmetric Top (simulation) Using Eulerian angles

, ,

Spinning symmetric top with its symmetry axis (), which is its spin axis as well as its principal axis of symmetry, at angle from the fixed axis

or

(b)

## solve numerically for

( t ) , ( t ) , ( t )

(a)

## 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

## Double Pendulum Coordinates

x1 = L1 sin 1 y1 = L1 cos 1

x2 = x1 + L2 sin 2 y2 = y1 + L2 cos 2

T=

## 1 1 2 2 12 + y 12 + m2 x 2 2 +y m1 x , V = m1 gL2 + m1 gh1 + m2 g ( h1 + h2 ) 2 2

L = T V = 1 1 2 2 2 2 2 2 1 + m2 m1 L1 L L + 1 1 2 2 + 2 L1 L21 2 cos (1 2 ) 2 2 m1 gL2 ( m1 + m2 ) gL1 (1 cos 1 ) m2 gL2 (1 cos 2 ) .

## 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) Three possible paths in the evolution process of the action integral t2 Hamiltons principle

I = Ldt = 0
t1

t2

S Ldt
t1

Hamiltons 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 S = Ldt = mv 2 mgy dt 2 2 t t

1 y yk tf with Lk L ( tk ) m k +1 N 1 mgyk 2 t S = Ldt t Lk y f y0 k =1 t0 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
2

( (

) )

## until dS is small. Compare numerical results against the exact solution

y = y0 + v0 t

1 2 gt 2

Simulation of Hamilton's least action principle for the case of the motion of a single particle free falling near Earth's surface, in one dimension

## See least_action.html and least_action.avi

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/

inter_spr1App

inter_spr2App

cycloid3dApp

foucaultApp

binary1App

rutherApp

topApp

doublepApp

least_actionApp