+ All Categories
Home > Documents > MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

Date post: 05-Jan-2016
Category:
Upload: justin-robbins
View: 221 times
Download: 0 times
Share this document with a friend
40
MA/CS 375 Fall 2002 1 MA/CS 375 Fall 2002 Lecture 12
Transcript
Page 1: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 1

MA/CS 375

Fall 2002

Lecture 12

Page 2: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 2

Office Hours

• My office hours– Rm 435, Humanities, Tuesdays from 1:30pm to 3:00pm– Rm 435, Humanities, Thursdays from 1:30pm to 3:00pm

• Tom Hunt is the TA for this class. His lab hours are now as follow

– SCSI 1004, Tuesdays from 3:30 until 4:45 – SCSI 1004, Wednesdays from 12:00 until 12:50 – Hum 346 on Wednesdays from 2:30-3:30

Page 3: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 3

This LectureSolving Ordinary Differential Equations (ODE’s)

• Accuracy• Stability

• Forward Euler time integrator• Runge Kutta time integrators

• Newton’s Equations

Page 4: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 4

Ordinary Differential Equation

• Example:

0

?

u a

duu

dt

u T

• t is a variable for time • u is a function dependent on t• given u at t = 0 • given that for all t the slope of us is –u• what is the value of u at t=T

Page 5: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 5

Ordinary Differential Equation

• Example:

0

?

u a

duu

dt

u T

• we should know from intro calculus that:

• then obviously:

tu t ae

Tu T ae

Page 6: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 6

Just in Case You Forgot How…

0 0

00

11

ln1

ln

ln

ln ln 0 0

0

T T

t T T

t

T

duu

dtdu

u dtd u

dt

d udt dt

dt

u t

u T u T

u T u e

ok if u!=0

ok if u>0

integrate in time

Fundamental theorem of calculus

Page 7: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 7

Family of Solutions

( ) (0) tu t u e

u(0)=4 curve

u(0)=-4 curvet

u(t)

Page 8: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 8

Forward Euler Numerical Scheme

• There are many ways to figure this out on the computer.

• Simplest first.

• We discretize the derivative by

du t u t t u t

dt t

Page 9: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 9

Forward Euler Numerical Scheme

• Numerical scheme:

• Discrete scheme:

1n nnu uu

t

1 1n nu t u where: approximate solution at t=n tnu

Page 10: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 10

Stability of Forward Euler Numerical Scheme

• Discrete scheme:

• The solution at the n’th time step is then:

1 1n nu t u

01

1 0

nn

n

u t u

t u

Page 11: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 11

Stability of Forward Euler Numerical Scheme

• The solution at the n’th time step is then:

• Notice that if then |un| is going to get very large very quickly !!. This is clearly not what we want for an approximate solution to an exponentially decaying exact solution.

01 1 0n nnu t u t u

1 1t

Page 12: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 12

Stable Approximations

• 0<dt<1

dt

dt=0.5

dt=0.25

dt=0.125

Page 13: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 13

Stable But Oscillatory Approximations

• 1<=dt<2

dt=1.25

dt=1.5dt=1.5

Page 14: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 14

Unstable (i.e. Bad) Approximations

• 2<dt

dt=4.5

dt=3

dt=2.5

Page 15: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 15

Summary of dt Stability

• 0 < dt <1 stable and convergent since as dt 0 the solution approached the actual solution.

• 1 <= dt < 2 bounded but not cool.

• 2 <= dt exponentially growing, unstable and definitely not cool.

Page 16: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 16

Accuracy of the Forward Euler Scheme

• Next lecture

Page 17: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 17

Application: Newtonian Motion

Page 18: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 18

Two of Newton’s Law of Motions

1) In the absence of forces, an object ("body") at rest will stay at rest, and a body moving at a constant velocity in straight line continues doing so indefinitely.

2) When a force is applied to an object, it accelerates. The acceleration a is in the direction of the force and proportional to its strength, and is also inversely proportional to the mass (m) being moved. In suitable units:

F = ma

with both F and a vectors in the same direction (denoted here in bold face).

Page 19: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 19

Newton’s Law of Gravitation

Gravitational force: an attractive force that exists between all objects with mass; an object with mass attracts another object with mass; the magnitude of the force is directly proportional to the masses of the two objects and inversely proportional to the square of the distance between the two objects.

Page 20: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 20

Real Application

• You can blame Newton for this:

2

2

F = ma

d x= a

dtdx

= vdtdv

= adt

Consider an object with mass m

t = timem = mass of objectF = force on objecta = acceleration objectx = location of objectv = velocity of object

Page 21: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 21

Two Gravitating Particle Masses

m1

m2

Each particle has a scalar mass quantitiy

Page 22: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 22

Particle Positions

x1

x2

(0,0)

Each particle has a vector position

Page 23: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 23

Particle Velocities

v1

v2

Each particle has a vector velocity

Page 24: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 24

Particle Accelerations

a1 a2

Each particle has a vector acceleration

Page 25: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 25

Definition of ||.||2

• In the following we will use the following notation:

• Formally the function ||x||2 known as the Euclidean norm of x. It returns the length of the vector x

2 2 31 2 22x x x x

Page 26: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 26

Two-body Newtonian Gravitation

• Two objects of mass M1 and M2 exert a gravitational force on each other:

where G is the gravitational constant.

2 1 1 212 3

2 1 2

1 2 2 121 3

1 2 2

M M G

M M G

x - xF

x - x

x - xF

x - x

Force exerted by mass 2 on 1:

Force exerted by mass 1 on 2:

Page 27: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 27

Newtonian Gravitation

• Newton’s second law (rate of change of momentum = force on body) :

21 1 2 1 1 2

32

2 1 2

22 2 1 2 2 1

32

1 2 2

d M M M G

dt

d M M M G

dt

x x - x

x - x

x x - x

x - x

Page 28: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 28

Newtonian Gravitation

• Acceleration:

22 1 21

32

2 1 2

21 2 12

32

1 2 2

M Gd

dt

M Gd

dt

x - xx

x - x

x - xx

x - x

Page 29: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 29

Newtonian Gravitation

• Using velocity:

11

22

2 1 213

2 1 2

1 2 123

1 2 2

d

dtd

dtM Gd

dt

M Gd

dt

xv

xv

x - xv

x - x

x - xv

x - x

Page 30: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 30

N-Body Newtonian Gravitation

• For particle n out of N

3

1,2

nn

i Ni n in

i i n i n

d

dtM Gd

dt

xv

x - xv

x x

The force on each particle is a sum of the gravitational force between each other particle

Page 31: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 31

N-Body Newtonian Gravitation Simulation

• Goal: to find out where all the objects are after a time T

• We need to specify the initial velocity and positions of the objects.

• Next we need a numerical scheme to advance the equations in time.

• Can use forward Euler…. as a first approach.

Page 32: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 32

Numerical Scheme

13

1,2

1

m mi Ni n im m

n nm m

i i n i n

m m mn n n

M Gdt

dt

x - x

v vx x

x x v

For m=1 to FinalTime/dt For n=1 to number of objects

End For n=1 to number of objects

EndEnd

Page 33: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 33

planets1.m Matlab script• I have written a planets1.m script.• The quantities in the file are in units of

– kg (kilograms -- mass)– m (meters – length)– s (seconds – time)

• It evolves the planet positions in time according to Newton’s law of gravitation.

• It uses Euler-Forward to discretize the motion. • All planets are lined up at y=0 at t=0• All planets are set to travel in the y-direction at t=0

Page 34: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 34

Parameters

Object masses:

Mean distancesfrom sun:

Page 35: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 35

Initial velocities of objects:

Page 36: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 36

Set dt:Time loop:

Calculateacceleration:

AdvanceX,Y,VX,VY

Plot the firstfour planetsand the sun

end Time loop

Page 37: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 37

Mercury

VenusEarth

Page 38: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 38

Mercury

VenusEarth

Mercury has nearly completed its orbit. Data shows 88 days. Run for 3 more days and the simulation agrees!!!.

Sun

Page 39: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 39

Team Exercise• Get the planets1.m file from the web site• This scripts includes:

– the mass of all planets and the sun– their mean distance from the sun– the mean velocity of the planets.

• Run the script, see how the planets run!• Add a comet to the system (increase Nsphere etc.) • Start the comet out near Jupiter with an initial velocity

heading in system.• Add a moon near the earth.• Extra credit if you can make the comet loop the sun

and hit a planet

Page 40: MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 12.

MA/CS 375 Fall 2002 40

Next Lecture

• More accurate schemes

• More complicated ODEs

• Variable time step and embedded methods used to make sure errors are within a tolerance.


Recommended