February 7, 2012 --- Class 9 --- Graphing the velocity ratio, Details of
root finding, Finding the initial height, Oscillatory Motion
Activities:
Graphing 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 the awk file ~sg/vel_ratio.a.
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 <