gnuplot 拟合 fit函数的用法

来源:互联网 发布:配电网优化运行 编辑:程序博客网 时间:2024/05/01 13:51

曲线拟合是gnuplot的强项,只需简单的两条命令就可以得到拟合的曲线。


假设我们想对数据进行线性拟合,数据存储在file.data 文件中,数据的第一列是x数据,第二列对应的是y的数据

输入下列两句命令,即可得到线性的拟合函数y(x)

y(x)=a*x+b
fit y(x)  file.data using 1:2 via a,b


输入plot y(x) 命令,便可以得到拟合后的结果。


例如:

set terminal eps truecolor font ",15"
set output "fit.eps"
set multiplot
set key top left
set key sample 1
set size 0.6,0.7
unset xtics
set ytics 20
y(x)=a*x+b
fit y(x) "1.out" using 1:2 via a,b
plot "1.out" using 1:2 with p ps 0.5 lw 2 lt 1 notitle, \
 y(x) with l lw 2 lt 2 notitle 


拟合后的曲线如下图:

0 0
原创粉丝点击