1

I would like to fit a function using many data sets. For example, I reproduce an experience many times, each time I obtain a pair of data column (x,y). I put all these column in a file named 'data.txt' :

first experience : x = column 1, y = column 2

second experience : x = column 3, y = column 4

third experience : x = column 5, y = column 6

...

Now I wish to fit a function y = f(x) for these data sets. I do not know if Gnuplot can do that ? If it is possible, could you please help me to correct the following command ? This one does not work.

fit f(x) "data.txt" u 1:2:(0.25), "data.txt" u 3:4:(0.25), "data.txt" u 5:6:(0.25) via a, b
2
  • Do you want each data set to be fit to a different set of fit parameters (e.g. polynomials with different coefficients), or do you want a shared set of fit parameters across all the data sets? Commented May 11, 2014 at 3:24
  • What I want to do as optimisation is the second choice : a shared set of fit parameters across all the data sets Commented May 11, 2014 at 6:16

1 Answer 1

3

You can process your data so that columns 1, 3 and 5 all become the same column 1, and columns 2, 4 and 6 all become the same column 2. It's easy with awk, you can do it outside gnuplot:

awk '{print $1, $2} {print $3, $4} {print $5, $6}' data.txt > data2.txt

and then fit it within gnuplot:

f(x)=a*x+b
fit f(x) "data2.txt" u 1:2:(0.25) via a,b

Or you can do it completely within gnuplot without any intermediate file:

f(x)=a*x+b
fit f(x) "< awk '{print $1, $2} {print $3, $4} {print $5, $6}' data.txt" u 1:2:(0.25) via a,b
Sign up to request clarification or add additional context in comments.

Comments

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.