我的gnuplot适合度很差,我该如何改善?

时间:2019-04-21 00:15:55

标签: gnuplot

我正在尝试使用gnuplot拟合函数a /(1 + b *(sin(c * x + d))** 2)+ e。结果是:

enter image description here

我的代码是

set terminal png
set output "lab7.png"

set xrange [7:42]
set yrange [.08:.3]
set xlabel "x"
set ylabel "I"
set title "I vs x"

f(x) = a/(1+b*(sin(c*x+d))**2)+e
fit f(x) "lab7_data.dat" via a,b,c,d,e 

plot "lab7_data.dat" t "data", f(x) t "fit"
exit

我如何使其更合适?

1 个答案:

答案 0 :(得分:0)

您应该问自己的第一个问题:您的数据是否完全可以与您的函数相匹配?

我看到的是阻尼振荡功能。 根据您的功能,x会产生振荡,但振幅没有衰减。

我的第一个猜测应该是像f(x) = a/(x-b) * sin(c*x+d) + e这样的函数。

### fit a function
reset session

$Data <<EOD
# Data approximately from OP's post
8.968   0.119
9.901   0.180
11.915  0.220
12.921  0.240
13.931  0.252
15.905  0.251
16.867  0.243
17.888  0.229
18.974  0.196
20.005  0.157
20.917  0.133
21.998  0.111
22.905  0.099
23.978  0.095
24.882  0.092
25.954  0.091
27.024  0.094
28.982  0.130
31.940  0.203
33.854  0.213
34.923  0.218
35.995  0.216
36.956  0.212
37.920  0.198
38.944  0.177
39.978  0.132
41.000  0.114
EOD

set xrange [7:42]
set yrange [.08:.3]
set xlabel "x"
set ylabel "I"
set title "I vs x"

a=1
b=1
c=2*pi/20
d=1
e=1

# f(x) = a/(1+b*(sin(c*x+d))**2)+e      # is this an appropriate function?
f(x) = a/(x-b) * sin(c*x+d) + e         # my guess
fit f(x) $Data via a,b,c,d,e 

plot $Data t "data" w p pt 7 lc rgb "red" , f(x) t "fit"
### end of code

结果:

enter image description here

Final set of parameters            Asymptotic Standard Error
=======================            ==========================
a               = 3.76651          +/- 0.8605       (22.85%)
b               = -23.8952         +/- 10.11        (42.31%)
c               = 0.319073         +/- 0.003908     (1.225%)
d               = 3.0736           +/- 0.08416      (2.738%)
e               = 0.160669         +/- 0.00242      (1.506%)