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.

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

Filed under: gnuplot | Tagged: fitting, gnuplot, polynomial, regression | 4 Comments »