September 15, 2005 --- Class 6 --- Euler-Richardson Algorithm; Multiple Plots; A Body Falling in a Position Dependent Potential Activities: Motivation for Euler-Richardson Algorithm We discussed how a numerical integral done via a Taylor series expansion about the midpoint of the interval results in an integration formula with no (dt)^2 term. This was used to motivate the Euler-Richardson algorithm that uses the acceleration and velocity at the midpoint of the time interval to update velocity and position through the whole time interval. You will get to implement the Euler-Richardson algorithm for homework. There is a program in the textbook. Another use for parentheses--- multiple axis graphs on one page In ~sg/three_graphs.csh is a shell script that uses axis to print three graphs on a single page. # (awk '{print $1,$2}' fall.dat |axis h .3 lx t ly y ; \ awk '{print $1,$3}' fall.dat |axis h .3 u .33 ly v -s ; \ awk '{print $1,$4}' fall.dat |axis h .3 u .66 ly a -s ) \ | plot -T x -s In this case there are three awk and axis commands in one set of parentheses. The awk commands pick out different columns from the same data file. The axis commands make each graph shorter with the -h command and graphs 2 and 3 are raised 1/3 and 2/3 of the page height with the -u option. Note that the second two graphs must use the -s option to save the page. Also you must add the -s option to plot, or it will complain or start a second plot window. (I have seen both on different systems.) The parentheses assure that all of the output from each axis command is sent as a single stream to plot, so there is only one xplot window with all three graphs. Discussion of an object falling in a position dependent potential We wish to solve is problem 3.4 of CSM. We drop a ball from high above the surface of the earth (neglecting air resistance!). From how great a height must we drop it so that it's velocity when it hits the ground is 1% different from what it would be assuming constant acceleration. There are several potential sources of error: 1) We know from the coffee cooling problem that when we do numerical integration there can be a step-size error. So we must be careful about this. 2) When we integrate the equations in time, we won't necessarily stop integrating exactly when the object reaches height 0. We may have to interpolate to find the velocity when the height is zero. 3) We also must find what height results in a 1% difference. Do we guess initial heights? How do we accurately find the height that corresponds to 1%? Step size error We have three approaches to the step size error issue. One possibility is to vary the step size and see how the answer varies. The accuracy on the velocity at height=0 must be much greater than 1%. The accuracy will depend on height and step size. We can also try to find a better method than Euler or Euler-Cromer. These are each first order methods. The Euler-Richardson method is one order higher. Try running this code with different step sizes. Note the accuracy of the energy and the position. (Interestingly, the difference is negligible for the velocity.) Another scheme involves using the Euler-Cromer algorithm with different step sizes to extrapolate to zero step size. This was described on the board and is coded in adapt_step.c. This code will increase or decrease the step size to achieve a desired level of accuracy during the integration. We will examine the code in adapt_step.c in my next lecture.