gpt4 book ai didi

Gnuplot 的计算不正确

转载 作者:行者123 更新时间:2023-12-04 04:34:49 27 4
gpt4 key购买 nike

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

我使用来自 Wikipedia 的公式和 Google gets a velocity at apoapsis of about 2.2 km/s .现在 gnuplot 本身的速度约为 3.2 公里/秒。

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

我想知道是我做错了吗?我直接把公式复制到谷歌,替换 G , MR使用常量值和 x与 100000 并获得上面链接的结果。

最佳答案

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

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

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

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

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

关于Gnuplot 的计算不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19915037/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com