Gnuplot(椭圆拟合)
我正在尝试使用gnuplot拟合椭圆 然而,当我定义我的方程式时Gnuplot(椭圆拟合),gnuplot,ellipse,Gnuplot,Ellipse,我正在尝试使用gnuplot拟合椭圆 然而,当我定义我的方程式时 f(x,y) = a*x*x + b*x*y + c*y*y + d*x + e*y + f 然后继续执行命令绘图: plot f(x,y) lw 3 lc rgb 'black', 'text.dat' w l lc rgb 'black' 我得到未定义的变量:y。我怎样才能修好它? text.dat有3列:x、y和z坐标。为了说明问题,假设要拟合的数据点存储在文件pnts.dat中(x、y坐标): 现在,目标是找到方程a*
f(x,y) = a*x*x + b*x*y + c*y*y + d*x + e*y + f
然后继续执行命令绘图:
plot f(x,y) lw 3 lc rgb 'black', 'text.dat' w l lc rgb 'black'
我得到未定义的变量:y
。我怎样才能修好它?
text.dat
有3列:x、y和z坐标。为了说明问题,假设要拟合的数据点存储在文件pnts.dat
中(x、y坐标):
现在,目标是找到方程
a*x*x+b*x*y+c*y*y+d*x+e*y+f=0中参数的最佳值。但是,如果在拟合过程中直接使用该方程,则结果很可能是所有参数都等于零,因为对于x,y的任何值,都会自动满足该方程。如果你对一个非退化椭圆感兴趣,它必须认为b*b-4*a*cyou应该看看parametricmode
:或者非常感谢!嘿,我需要一个额外的z轴柱吗?每次我尝试绘图时,它都会给出“z轴范围未定义”。此外,我似乎没有正确读取中的值,因为在使用fit命令时,我一直获取-nan和-inf值。有什么想法吗?谢谢
-2.000000 -0.005494
-1.789474 -0.410310
-1.578947 -0.616013
-1.368421 0.760577
-1.157895 0.695609
-0.947368 0.921957
-0.736842 -0.882355
-0.526316 -1.031450
-0.315789 -0.910362
-0.105263 -0.986339
0.105263 -0.897862
0.315789 -1.059766
0.526316 -1.007012
0.736842 0.910494
0.947368 -0.878432
1.157895 0.823232
1.368421 0.831900
1.578947 -0.662069
1.789474 0.427903
2.000000 -0.001474
f(x, y) = x*x + b*x*y + c*y*y + d*x + e*y + f
fit f(x, y) 'pnts.dat' u 1:2:(0) via b,c,d,e,f
set contour
set view map
unset surface
set cntrparam levels discrete 0
set isosamples 1000,1000
set table 'contour.dat'
splot f(x, y)
unset table
unset contour
set terminal pngcairo enhanced
set output 'fig.png'
set xr [-3:3]
set yr [-3:3]
set size square
plot \
'contour.dat' u 1:2 w l lw 2 lc rgb 'red', \
'pnts.dat' u 1:2 w p ps 1.5 lc rgb 'black'