0

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Ah! Yes, I just mistyped fir, oops. I will use the errors to get a better fit then!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.