Gnuplot behaves oddly in polynomial fit. Why is that?

前端 未结 2 708
闹比i
闹比i 2021-02-08 14:54

A friend of mine discovered some odd behavior in gnuplot regarding a simple polynomial fit Can sombody explain this?

Here is the file:

#!/usr/bin/gnuplot         


        
2条回答
  •  时光取名叫无心
    2021-02-08 15:38

    Just try the code below. The trick is to ensure that the range of the x and the y variables are of the same order of magnitude.

    reset;
    plot 'data.txt' u ($1+273.14):2 w p;
    f(x, a, b) = a*(1e-2*x)**4 + b; # note the 1e-2 multiplicative factor
    a = 1; b = 1; # initial parmeters
    fit f(x,a,b) 'data.txt' u (($1+273.14)):2 via a, b
    #plot 'data.txt' u (($1+273.14)):2 w p, f(x, a, b) w l
    plot 'data.txt' u (($1+273.14)):2 w p, (a*(1e-2)**4)*x**4+b w l
    print sprintf("Fit parameters for the fit function a*x^4 + b are :\n\ta = %e, \n\tb = %f", a*(1e-2)**4, b)
    

    Image of the graph

提交回复
热议问题