如何在gnuplot中转换原点?

如何在gnuplot中转换原点?,gnuplot,Gnuplot,这是我的数据。 而y(x)=a/(b**2+x**2)**3/2是我想要拟合上述数据的方程,但我面临的问题是b的值为负值。因此,我想知道如何更改图表的原点以获得正确的结果,我不确定,但我认为您试图拟合的方程可能不适合数据。也许你可以改写你的方程式,使它更清晰 下面是一个使用二次方程y(x)=a*x**2+b*x+c拟合的示例: 测试.dat B x(cm) 24.5 4.2 25.5 4.5 26.5 5.0 27.5 5.4 28.5 5.9 29.

这是我的数据。
y(x)=a/(b**2+x**2)**3/2
是我想要拟合上述数据的方程,但我面临的问题是b的值为负值。因此,我想知道如何更改图表的原点以获得正确的结果,我不确定,但我认为您试图拟合的方程可能不适合数据。也许你可以改写你的方程式,使它更清晰

下面是一个使用二次方程
y(x)=a*x**2+b*x+c
拟合的示例:

测试.dat

B        x(cm)
24.5    4.2
25.5    4.5
26.5    5.0
27.5    5.4
28.5    5.9
29.5    6.6
30.5    7.2
31.5    7.9
32.5    8.6
33.5    9.3
34.5    10.0
35.5    10.5
36.5    10.9
37.5    11.1
38.5    11.1
39.5    10.8
40.5    10.3
41.5    9.8
42.5    9.2
43.5    8.4
44.5    7.7
45.5    7.1
46.5    6.4
47.5    5.9
48.5    5.4
49.5    5.0
50.5    4.6
51.5    4.2
quad_-fit.gp

24.5 4.2
25.5 4.5
26.5 5.0
27.5 5.4
28.5 5.9 
29.5 6.6 
30.5 7.2 
31.5 7.9 
32.5 8.6 
33.5 9.3 
34.5 10.0 
35.5 10.5 
36.5 10.9 
37.5 11.1 
38.5 11.1 
39.5 10.8 
40.5 10.3 
41.5 9.8 
42.5 9.2 
43.5 8.4 
44.5 7.7 
45.5 7.1 
46.5 6.4 
47.5 5.9 
48.5 5.4 
49.5 5.0 
50.5 4.6 
51.5 4.2 
运行
gnuplot quad_fit.gp
会产生: 有几件事:

  • 你确定函数是
    f(x)=a/(b**2+x**2)**3/2
    而不是
    f(x)=a/(b**2+x**2)**(3/2)
    ,请注意
    (3/2)
    周围的括号
  • gnuplot具有整数除法(意外结果的常见陷阱),因此,
    (3/2)
    将被计算为
    1
    ,而不是预期的
    1.5
  • 为什么不让gnuplot找到偏移量呢?只需引入一个变量
    c
    ,它将计算x偏移量并使其适合
  • 根据您的模型,即如果指数是可变的,您还可以为指数添加一个变量
    d
    ,并让它通过gnuplot拟合算法进行查找
  • 有时,如果你用良好的起始值来帮助拟合,效果会更好
  • 然后,您必须判断拟合值是否合理,例如
    b
    
    set term pos col
    set out 'xy_fit.ps'
    
    set title 'Quadratic Regression Example Scatterplot'
    set ylabel 'Y'
    set xlabel 'X'
    set style line 1 ps 1.5 pt 7 lc 'red'
    set style line 2 lw 1.5 lc 'blue'
    
    set grid
    
    f(x) = a*(x**2) + b*x + c
    fit f(x) 'test.dat' using 1:2 via a, b, c
    
    p 'test.dat' ls 1 t 'Datapoints', f(x) ls 2 t 'Quadratic Regression'
    set out
    
    ### fitting with finding x-offset automatically
    reset session
    
    $Data <<EOD
    B        x(cm)
    24.5    4.2
    25.5    4.5
    26.5    5.0
    27.5    5.4
    28.5    5.9
    29.5    6.6
    30.5    7.2
    31.5    7.9
    32.5    8.6
    33.5    9.3
    34.5    10.0
    35.5    10.5
    36.5    10.9
    37.5    11.1
    38.5    11.1
    39.5    10.8
    40.5    10.3
    41.5    9.8
    42.5    9.2
    43.5    8.4
    44.5    7.7
    45.5    7.1
    46.5    6.4
    47.5    5.9
    48.5    5.4
    49.5    5.0
    50.5    4.6
    51.5    4.2
    EOD
    
    f1(x) = a1/(b1**2 + (x-c1)**2)**(3/2)
    f2(x) = a2/(b2**2 + (x-c2)**2)**(3./2)
    f3(x) = a3/(b3**2 + (x-c3)**2)**d3
    
    set fit quiet nolog
    fit f1(x) $Data u 1:2 via a1,b1,c1
    fit f2(x) $Data u 1:2 via a2,b2,c2
    a3=11; b3=1; c3=40; d3=1.5             # sometimes it's better to help the fitting with some good starting values
    
    fit f3(x) $Data u 1:2 via a3,b3,c3,d3
    
    
    print sprintf("% 9s% 9s% 9s% 9s","a","b","c","d")
    print sprintf("%9.3g %9.3g %9.3g",a1,b1,c1)
    print sprintf("%9.3g %9.3g %9.3g",a2,b2,c2)
    print sprintf("%9.3g %9.3g %9.3g %9.3g",a3,b3,c3,d3)
    
    plot $Data u 1:2 w p pt 7,\
         f1(x) w l lc "red",\
         f2(x) w l lc "web-green", \
         f3(x) w l lc "web-blue"
    ### end of code
    
            a        b        c        d
     1.17e+03      10.3      37.9
     2.73e+04     -13.6      37.9
          343      8.66      37.9     0.794