September 22, 2005 --- Class 7 --- A Body Falling in a Position
Dependent Potential (continued), Graphing the velocity ratio
Activities:
Discussion of an object falling in a position dependent potential
In view of the length of time since we last discussed this
problem, we reviewed what we previously discussed.
We wish to solve 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 examined the code in adapt_step.c to see how it increases
or decreases the step size depending on how accurately our two
estimates of the velocity agree with each other. We then ran
the code with different initial step sizes and found that the
step size could increase or decrease depending up whether we
picked too large or too small an initial step size.
Extrapolation back to height = 0
Since the integration goes to the next print time and we stop
when the height is negative, we need to find the velocity when
the height is zero. It is easy to do this neglecting the
acceleration. However, if the print time is large, this may
become a dominant source of error. We examined this by testing
different print times.
A second code, to extrapolate back to height = 0, using uniform
acceleration was discussed. The
code is in ~sg/adapt_step_nonlin_interp.c. We compiled the
code and ran it to verify that it improves the calculation of
the velocity at height = 0.
Finding the ratio to the naive velocity
The problem is stated in terms of the ratio of the velocity in
the position dependent potential as compared with constant
acceleration g. Of course, we can find the velocity with
constant acceleration, so the code currently prints that out
on a line by itself after the velocity from integration with
the position dependent acceleration is printed. We may use
AWK to get the ratio of velocities.
We use the awk file ~/sg/vel_ratio.a. It contains two lines:
/^V/{vel=-$4; rec=NR}
NR==rec+1 && NR >1 { ratio =vel/$1; print ratio}
We next ran the adapt_step program with several guesses for the
initial height and found that as we increase the height the
ratio of velocity in a position dependent potential to velocity
assuming constant acceleration g is decreasing. It is a bit
boring to keep guessing values that will get us to 0.99 as the
ratio, so we realized that we are really trying to find the
root of an equation:
ratio( height) = 0.99,
and we need to find the value of height that solves this
equation.
Graphing the velocity ratio as function of the height via shell script
It is relatively easy to make a graph of the velocity ratio
as a function of the initial height. We can use a foreach
loop to set the initial height. Then, we need to manipulate
the output of adapt_step to get the velocity ratio. This
last step is done with an awk script. The
awk file ~sg/vel_ratio.a contains two lines:
/^V/{vel=-$4; rec=NR}
NR==rec+1 && NR >1 { ratio =vel/$1; print ratio}
Below is a shell script to run adapt_step and pipe the output
through awk. If you run this at the screen, you will
find all the prompts from adapt_step, which are written
to the standard error, mixed up with the output from the
awk script, which are written to the standard output.
If you redirect the standard output to a file with the ">"
symbol, only the output you want will wind up in the file.
#!/bin/csh
foreach height ( 20000 40000 60000 80000 100000 120000 140000 160000)
echo -n $height " "
adapt_step <