O'Reilly logo

gnuplot Cookbook by Lee Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fitting functions to your data

If we want to get serious about fitting functions to our data, we can turn to gnuplot's sophisticated fit command.

Getting ready

You need the same datafile used in the previous recipe, rs.dat. The following figure shows the same noisy sine wave, but this time the overlaid curve seems to be perfectly smooth:

Getting ready

How to do it…

The following script will produce the previous figure:

f(x) = a*sin(b*x)
fit f(x) 'rs.dat' via a, b
plot 'rs.dat' with lines lw 0.5 notitle, f(x) lw 4 title "Fit by gnuplot"

How it works…

gnuplot's fit command takes a function defined by the user containing several parameters and attempts to find the set ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required