Gnuplot:将椭圆拟合到极坐标中的数据集

Gnuplot: Fit an ellipse to a dataset in polar coordinates

对于一项作业,我需要绘制一个物体的惯性椭球体。 为此,我绘制了惯性对 angular 旋转的倒数。完成后,我需要用椭圆拟合绘图。

但是我不能在 deg 模式下绘制我的数据集,只能在 rad 模式下绘制,我不知道为什么我的代码不起作用。我还需要帮助来绘制椭圆。

这是我的代码:

set terminal png
set output 'tisch.png'

set angles radians
set polar
show polar
set parametric
set grid polar
set size square
set trange [0:360]
set rrange [0:0.5]

plot 'A3-daten.txt'  

这是我的数据集:

0       0.494012339
30      0.510681467
60      0.461169413
90      0.42190106
120     0.408044505
150     0.442066272
180     0.496961666

预先感谢您的帮助,对于我的语法错误深表歉意,英语是我的 second/third 语言,尽管我能够很好地理解,但有时我仍然难以用英语表达自己可以理解的方式。

在极坐标模式下,gnuplot 可以拟合和绘制形式为 r(t) 的函数,其中 t 是角度,r 是距原点的距离。这意味着我们必须使用这种形式来表达一个椭圆。

接下来我们咨询Wikipedia。在这里我们必须要小心:Wikipedia 使用的 t 用于椭圆的参数表示是 而不是 gnuplot 使用的角度 t,他们称它为 "eccentric anomaly"。使用 tw 代替,参数表示是:

x = a*cos(tw)
y = b*sin(tw)

我们可以将这些方程式转换为 gnuplot 所需的极坐标表示(已知的从笛卡尔坐标到极坐标的转换):

r = sqrt( x**2 + y**2 )
  = sqrt( (a*cos(tw))**2 + (b*sin(tw))**2 )

tan(t) = y/x
       = (b*sin(tw)) / (a*cos(tw))

我们需要tw,所以我们求解第二个方程:

sin(tw) / cos(tw) = (a*sin(t)) / (b*cos(t))
          tan(tw) = (a*sin(t)) / (b*cos(t))
               tw = atan2( a*sin(t), b*cos(t))

可以使用 t-phi 而不是 t 来旋转椭圆。

现在我们已经完成了数学方程式的转换,我们可以从 gnuplot 开始了。脚本很简单:

datafile = "A3-daten.txt"                                  

set terminal pngcairo                                      
set output "ellipse.png"                                   
set size square                                            

tw(t) = atan2(a*cos(t-phi),b*sin(t-phi))                
r(t) = sqrt( (a*cos(tw(t)))**2 + (b*sin(tw(t)))**2 ) 

set polar
set angles degrees                                         

fit r(t) datafile via a,b,phi                              
plot datafile title datafile ls 7, r(t) title "Fit"

我到达:

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = 0.408469         +/- 0.001589     (0.3889%)
b               = 0.51369          +/- 0.001782     (0.3469%)
phi             = 21.0673          +/- 0.7251       (3.442%)