I wanted an equation to summarise the following data so that it could conveniently be used for some calculations, after many attempts I found that I could fit the data using 2, 6 order polynomials. One was fitted on the data between x = 0-200 and another in the range x = 200-900.

1 polynomial equation after fitting.

Second polynomial equation after fitting.

Final polynomial equations after fitting.

Source files

set terminal png

set output "HH.png"

```
```#set cntrparam cubicspline

#set cntrparam order 2

#plot "HH.DAT" using 1:2:(1.0) smooth acsplines title "acsplines"

#sw(x,S)=1/(x*x*S)

#plot "HH.DAT" using 1:2 smooth csplines title "csplines"

#plot "HH.DAT" using 1:2 smooth bezier title "bezier"

#plot "HH.DAT" using 1:2 smooth sbezier title "sbezier"

#plot "HH.DAT" using 1:2 smooth unique title "unique"

#plot "HH.DAT" using 1:2 smooth frequency title "frequency"

# Linear Regression

#f(x) = m*x+c

#fit f(x) "HH.DAT" via m,c

#plot "HH.DAT", f(x)

#f(x) = a + b*x + c*x**2 + d*x**3 + e*x**4 + f*x**5

#fit f(x) "HH.DAT" via a,b,c,d,e,f

#plot "HH.DAT" ps 0.1, f(x)

a = 100

f(x) = a + b*x + c*x**2 + d*x**3 + e*x**4 + f*x**5 + g*x**6

fit [200:900] f(x) "HH.DAT" via a,b,c,d,e,f,g

plot "HH.DAT" ps 0.1 , f(x)

#g(x) = h * exp (((x-j)*(x-j))/(2*i*i))

#g(x) = h + j*x + i*x**2

g(x) = h + i*x + j*x**2 + k*x**3 + l*x**4 + m*x**5 + n*x**6

fit [0:200] g(x) "HH.DAT" via h,i,j,k,l,m,n

set yrange [-2000:10000]

set output "HH2.png"

plot "HH.DAT" ps 0.1, g(x)

set output "HH3.png"

h(x) = (x<200 ? g(x) : f(x))

plot "HH.DAT" ps 0.1, h(x)

show variables

### Like this:

Like Loading...

*Related*

Filed under: gnuplot | Tagged: fitting, gnuplot, polynomial, regression |

shocked, on 4 August, 2008 at 7:34 pm said:this is sensational

sree, on 30 December, 2008 at 3:45 pm said:good.

last figure link going to the second one. it should link to HH3.png

Ilahi, on 8 February, 2012 at 4:56 pm said:i request how i can fitted a complex expression with gnuplot,i can deffined the complex i

mathew, on 8 February, 2012 at 5:48 pm said:What is the expression you want to fit?

Mathew, on 10 June, 2018 at 8:22 pm said:Oh I see, there is actually an answer here: https://stackoverflow.com/questions/15851842/gnuplot-and-complex-exponentials