Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 13."— Presentation transcript:

1 MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 13

2 MA/CS 375 Fall 20022 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

3 MA/CS 375 Fall 20023 Ordinary Differential Equation Example: we should know from intro calculus that: then obviously: Review

4 MA/CS 375 Fall 20024 Forward Euler Numerical Scheme Numerical scheme: Discrete scheme: where: Review

5 MA/CS 375 Fall 20025 Direct Proof of Convergence Fix T and let delta t drop to zero In this case n needs to increase to infinity Review

6 MA/CS 375 Fall 20026 Stable Approximations 0<dt<1 dt dt=0.5 dt=0.25 dt=0.125 Review

7 MA/CS 375 Fall 20027 Application: Newtonian Motion Review

8 MA/CS 375 Fall 20028 Two Gravitating Particle Masses m1m1 m2m2 Each particle has a scalar mass quantity Review

9 MA/CS 375 Fall 20029 Particle Positions x1x1 x2x2 (0,0) Each particle has a vector position Review

10 MA/CS 375 Fall 200210 Particle Velocities v1v1 v2v2 Each particle has a vector velocity Review

11 MA/CS 375 Fall 200211 Particle Accelerations a1a1 a2a2 Each particle has a vector acceleration Review

12 MA/CS 375 Fall 200212 N-Body Newtonian Gravitation For particle n out of N The force on each particle is a sum of the gravitational force between each other particle Review

13 MA/CS 375 Fall 200213 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. Review

14 MA/CS 375 Fall 200214 Numerical Scheme For m=1 to FinalTime/dt For n=1 to number of objects End For n=1 to number of objects End Review

15 MA/CS 375 Fall 200215 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 Review

16 MA/CS 375 Fall 200216 Mercury Venus Earth Mercury has nearly completed its orbit. Data shows 88 days. Run for 3 more days and the simulation agrees!!!. Sun Review

17 MA/CS 375 Fall 200217 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 Today

18 MA/CS 375 Fall 200218 This Lecture More accurate schemes More complicated ODEs Variable time step and embedded methods used to make sure errors are within a tolerance.

19 MA/CS 375 Fall 200219 Adams-Bashforth Schemes In the forward Euler scheme we only used the value of the right hand side at the previous time step. i.e. we only used a linear approximation to the time derivative

20 MA/CS 375 Fall 200220 AB Schemes Idea: we set where If interpolates f n,f n-1,f n-2,..,f n+1-Nstages i.e.:

21 MA/CS 375 Fall 200221 f0f0 f1f1 f2f2 f3f3 We interpolate the function through the first 4 points. Then we integrate under the curve between t=3 and t=4.

22 AB Schemes Essentially we use interpolation and a Newton-Cotes quadrature formula to formulate:

23 MA/CS 375 Fall 200223 Runge-Kutta Schemes See van Loan for derivation of RK2 and RK4. I prefer the following (simple) scheme due to Jameson, Schmidt and Turkel (1981):

24 MA/CS 375 Fall 200224 Runge-Kutta Schemes Beware, it only works when f is a function of y and not t here s is the order of the scheme.

25 MA/CS 375 Fall 200225 Error Estimate Matlab has a number of time integrators built in. ode23 ode45 and others..

26 MA/CS 375 Fall 200226 ode23 For n=1:#timesteps –ode23 uses two estimates for y n+1. –A 2 nd order RK scheme and a 3 rd order RK scheme are used to build two guesses for y n+1. –If the difference between these two estimates are within a tolerance ode23 progresses on to calculating y n+2 –If the difference is greater than the specified tolerance, ode23 reduces the dt and tries again. It repeats until the difference is lower than the tolerance. End

27 MA/CS 375 Fall 200227 Planets Example Using ode23 Idea: replace our home grown Euler Forward scheme with Matlab’s ode23 scheme in the planets1.m script.

28 MA/CS 375 Fall 200228 Parameters for the planets as before

29 MA/CS 375 Fall 200229 Initial velocities Gather X,Y,VX,VY into one vector

30 MA/CS 375 Fall 200230 [T,CoordVel] = ode23(‘forcing’, TimeLimits, CoordVel(:)); Call to Matlab ode23 function function which calculates f(y) [0 FinalTime] Vector holds X,Y,VX,VY Works in Matlab v6.1.0 … at least

31 MA/CS 375 Fall 200231 Call to ode23 Find out the time at each time step Extract final coordinates and velocities Plot planet orbits

32 MA/CS 375 Fall 200232 The routine which calculates the forcing function.

33 MA/CS 375 Fall 200233 Team Exercise Grab planets2.m and forcing.m from the http://useme.org/MA375.html Run the script Use the Tsteps vector to find out the time step for each integration stage. Plot a graph showing the time step (dt) at each time step. Use help to find out how to change the tolerance used by ode23 (hint you will need to use odeset) Rerun the simulation with a tolerance of 0.1

34 MA/CS 375 Fall 200234 Application: One-Dimensional Electrostatic Motion

35 MA/CS 375 Fall 200235 Charge Repulsion Now we will consider the case of charged particles with the same sign charge Instead of attracting each other, the charges repel each other.

36 MA/CS 375 Fall 200236 Particle Accelerations a1a1 a2a2 Each particle has a vector acceleration directly away from the other particle

37 MA/CS 375 Fall 200237 Team Project Q1) Modify the planets2.m and forcing.m to simulate the following: –There are N electrically charged particles confined to move in the x-direction only –Distribute the charges initially at equispaced points in [-1,1] –The equations of motion of the charges are:

38 MA/CS 375 Fall 200238 Team Project Report Required on 9/25/02 Q1cont) Include the following in one project write up per team: –A scatter plot, with x as the horizontal axis and t as the vertical axis, showing the paths of all the charged particles using ode23 –A graph showing the size of each time step used by ode23 –Replace ode23 with ode45 and rerun –Plot the ode23 and ode45 (t,x) paths on the same graph. –Plot the ode23 and ode45 time step sizes on the same graph –Names of team members


Download ppt "MA/CS 375 Fall 20021 MA/CS 375 Fall 2002 Lecture 13."

Similar presentations


Ads by Google