Omega
Omega

Reputation: 33

Gnuplot: adding functions to a fit

I would like to know how I can add 2 seperate functions of 2 different plots to form the fit for the 3rd one?

I am using Gnuplot 4.6.3.

So, I have the following functions: f(x)=a+bx, g(x)=c+dx.

Now the third plot is the total of the first and the second plot added together. So, how can I add the fits together and plot it to form the fitting of the third one?

What I have tried so far:

gnuplot> f(x)=a+b*x
gnuplot> g(x)=c+d*x
gnuplot> fit [:] [:] f(x) 'filename1.dat' u 1:(log(-$2)) via a,b 
gnuplot> fir [:] [:] g(x) 'filename2.dat' u 1:(log(-$2)) via c,d
I get results for the variables a,b,c,d. 
gnuplot> plot 'filename1.dat', f(x) via a,b
gnuplot> replot 'filename2.dat', g(x) via c,d
gnuplot> replot 'filename1+2.dat', f(x)+g(x)

The 3rd fit is completely off, so I know I did something wrong, but what?

Thank you!

Upvotes: 0

Views: 517

Answers (1)

Joce
Joce

Reputation: 2332

The commands you list do exactly what you expect.

One likely error in your post (and possibly in the commands you issued in gnuplot) is that fits is done for 1:(log(-$2)) and not the plot of the data. But then, you also have fir for fit, and via in plot must raise errors.

Without more information on your data, it is difficult to spot another problem.

Upvotes: 1

Related Questions