【问题标题】:Gnuplot's calculation is incorrectGnuplot 的计算不正确
【发布时间】:2013-11-11 20:12:43
【问题描述】:

我尝试用 gnuplot 绘制轨道速度,但不知何故 gnuplot 得到的结果与我完全不同。现在根据经验,我认为我的值是正确的,但我用谷歌的计算器检查了它并得到了我的结果。

我使用来自Wikipedia 和Google gets a velocity at apoapsis of about 2.2 km/s 的公式。现在 gnuplot 本身的速度约为 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

我想知道我是否犯了错误?我将公式直接复制到 Google,并将 G、M 和 R 替换为常量值,将 x 替换为 100000,并得到上面链接的结果。

【问题讨论】:

    标签: gnuplot orbital-mechanics


    【解决方案1】:

    这个问题与 gnuplot 在进行算术运算时如何处理整数有关。当你有一个像1/(90000 + R) 这样的表达式时,如果R 是一个整数,gnuplot 会计算1/(690000) = 0,这是完全有效的整数运算。解决方案是在数字上添加句点,以便 gnuplot 知道将其转换为浮点数:

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

    另一种解决方案是对大数字使用电子符号:

    R = 6e5
    

    Gnuplot 将其视为浮点数。这也有助于防止数量级/零数错误。

    顺便说一句,python 和其他语言在整数运算方面也有同样的问题——小心!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      相关资源
      最近更新 更多