Domanda

I try to plot the orbital velocity with gnuplot, but somehow gnuplot gets completely different results than me. Now from experience I think my values are correct but I checked it with Google's calculator and get my results.

I use the formula from Wikipedia and Google gets a velocity at apoapsis of about 2.2 km/s. Now gnuplot itself gets a velocity of about 3.2 km/s.

set xlabel "Altitude above sea level (meters)"
set ylabel "Orbital velocity (meters per second)"
set title "Velocity of an 80×100 km orbit around Kebrin"
set terminal png size 800,640
set output "orbitv.png"
set xrange [80000:100000]
G=6.674*10**-11
M=5.2915793*10**22
R=600000
plot sqrt(G*M*(2/(x+R)-1/(90000+R))) title 'Orbital velocity' with lines

This is the resulting graph

I'm wondering were did I make the mistake? I copied the formula directly to Google and replaced G, M and R with the constant values and x with 100000 and get the result linked above.

È stato utile?

Soluzione

This problem has to do with how gnuplot handles integers when doing arithmetic. When you have an expression like 1/(90000 + R), if R is an integer, gnuplot evaluates 1/(690000) = 0, which is perfectly valid integer arithmetic. The solution is to add a period to a number so that gnuplot knows to cast it as a floating-point number:

R = 600000.     # short option
R = 600000.0    # clearer option

Another solution is to use e-notation for big numbers:

R = 6e5

Gnuplot treats that as a float. This also helps prevent order-of-magnitude/number-of-zeroes errors.

Incidentally, python and other languages have the same problem with integer arithmetic--watch out!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top