【发布时间】:2014-06-20 00:06:51
【问题描述】:
我正在使用以下 gnuplot 脚本来绘制线性拟合:
#!/usr/bin/gnuplot
set term cairolatex
set output "linear_fit.tex"
c = 299792458.
x(x) = c / x
y(x) = x
h(x) = a * x + b
fit h(x) "linear_fit.dat" u (x($1)):(y($2)) via a,b
plot "linear_fit.dat" u (x($1)):(y($2)) w points title "", \
(h(x)) with lines linecolor rgb "black" title "Linear Fit"
但是,在迭代收敛后,b 始终为 1.0:https://dpaste.de/ozReq/
如何让 gnuplot 调整 b 和 a?
更新: 重复 fit 命令几百次并交替使用 via a/via b 确实会产生很好的结果,但这不可能是应该的。
更新2:这是linear_fit.dat中的数据:
# lambda, V
360e-9 1.119
360e-9 1.148
360e-9 1.145
400e-9 0.949
400e-9 0.993
400e-9 0.971
440e-9 0.883
440e-9 0.875
440e-9 0.863
490e-9 0.737
490e-9 0.728
490e-9 0.755
540e-9 0.575
540e-9 0.571
540e-9 0.592
590e-9 0.457
590e-9 0.455
590e-9 0.482
【问题讨论】:
-
能否提供
linear_fit.dat的样本和一组典型的命令行输入$1和$2,好吗?我只是用“自制”linear_fit.dat尝试了这个,但无法重现您的观察结果。 -
@Schorsch 我用
linear_fit.dat的链接更新了问题。$1和$2不是指命令行输入,它只是表示gnuplot应该使用输入数据集的第一列和第二列。
标签: gnuplot