Fitting polynomial equations with gnuplot

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.

Final polynomial equations fit.

1 polynomial equation after fitting.

Final polynomial equations fit.

Second polynomial equation after fitting.

Final ploynomial equations fit.

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

Advertisements

4 Responses

  1. this is sensational

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

  3. i request how i can fitted a complex expression with gnuplot,i can deffined the complex i

  4. What is the expression you want to fit?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: