lsqcurvefit for several data sets at once

5 views (last 30 days)
Hello,
I would like to generate a function using lsqcurvefit. I do have a few data sets from several experiments. Every experiment has different parameters and one variable. Now I would like to generate a function with lsqcurvefit. But I want this function to be optimised for all data sets at once. Is there a way to do this? Or should I use another tool for that?
For example my data looks like this:
% Experiment 1
a1 = 0.416;
b1 = 2;
c1 = 2;
x1 = [0 0.33 0.67 1 1.33 2];
y1 = [1 0.89 0.8 0.44 0.62 0.37];
% Experiment 2
a2 = 0.801;
b2 = 0.67;
c2 = 4;
x2 = [0 0.17 0.33 0.5 0.67];
y2 = [1 0.8 0.84 0.83 0.81];
% and so on...
Thanks for your answers!
  4 Comments
Adam Danz
Adam Danz on 11 Mar 2019
Edited: Adam Danz on 11 Mar 2019
So you'd like to combine the data across experiments and fit it is one large data set? You mentioned that data from each experiment has different parameters which would potentially weaken the goodness of fit and/or variance of the data. Maybe I don't understand still. What would your inputs look like?
Fabian Hartmann
Fabian Hartmann on 11 Mar 2019
Yes you´re right, I would like to combine them into one large data set. I know I wouldnt get the best fit for the function but I need one function that works for all experiments.
In my example from before I have the constants a, b and c for experiment 1-5. Then I have my variable x and the result y for experiment 1-5.
The function I would like to have could look like this:
fun = @(xi,x)x(1)*exp(x(2)*xi/b1)+x(3)*(ai/ci)
% with i = 1, 2, 3, 4, 5
This function should be optimised for all data sets at once and just give me one value for x(1) , x(2), x(3) which fit all data sets.
I hope you can understand my explanation.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 11 Mar 2019
Edited: Adam Danz on 12 Mar 2019
Continuing from the comment section under the question, to combine data sets (x1, x2....) and (y1, y2, ...) just combine them in the same order to preserver the 1:1 correspondence between the xdata and ydata inputs. For the x0 initial starting points and the upper/lower bounds, you should systematically choose the best options from your individual data sets.
x = lsqcurvefit(fun,x0,[x1, x2], [y1, y2],lb,ub)
  7 Comments
Fabian Hartmann
Fabian Hartmann on 12 Mar 2019
I was hoping to skip the step of comparing each coefficient and have matlab figure out what works best for all. But thanks a lot, your answers have already helped me a lot.
Adam Danz
Adam Danz on 12 Mar 2019
Edited: Adam Danz on 12 Mar 2019
I enjoying helping and I learn a lot by doing so. It seems that the question you're asking isn't quite clear and I think the questions should be rock solild before you start with the solutions. For example, if you're trying to measure the difference in performance between the different concretes, you could fit a function to each data set and plot out the coefficients to determine the influence of each parameter on each concrete type. If you're just determining if there is a statistically significant difference between the concrete types a simple analysis of variance would be a better measure than curve fitting.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!