September 21, 2006 --- Class 8 --- Printing From Nations to Lindley, A Body Falling in a Position Dependent Potential (continued), Graphing the velocity ratio Activities: Printing a Nations file in Lindley The system manager finally told me how to print from nations to Lindley. On Nations, use this command: lp -d bl-uits-porkpie.ads.iu.edu:lh030prt file.ps The file should be a PostScript file. I tried a plain text file and it did not work. To convert a text file to PostScript, use the enscript command enscript -o file.ps file.txt Then you can print the Postscript file as above. I set up an alias and put it in my .alias file so I don't need to remember the long lp command: alias lh030 'lp -d bl-uits-porkpie.ads.iu.edu:lh030prt' Now, I just need to type: lh030 file.ps and the file is printed in the Lindley 030 Apple cluster. Discussion of an object falling in a position dependent potential In our last class we discussed in detail the adaptive step size algorithm and code adapt_step.c to integrate the equations of motion for a falling body in a position dependent potential. We ran 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. With different initial step sizes and print times, we found that the step size could increase or decrease depending up whether we picked too large or too small an initial step size. Sometimes the print time prevented the step size from increasing because there would not a integer number of steps between print times. 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 <