How to fit a number of curves

Hi,
I have a number of curves that have the same trend and relatively close to one another on the same plot and wish to fit these curves so that they can be represented by a single curve. Please advise me on how to do it.
Thanks
Isa

 Accepted Answer

Walter Roberson
Walter Roberson on 27 Dec 2012
You could fit the mean (or the median) of the curves. But if you wish to give more importance to larger deviations from the mean, then you would use different techniques.
What kind of curve are you planning to fit?

7 Comments

Thanks. I am trying to fit 6 power law curves. Can you explain further on fitting the mean or median of the curves and other different techniques you earlier mentioned.
Regards,
Isa
Are the curves all sampled at the same timepoints (or same x) ? If so, then put all of the data in a single matrix and take the median() across the appropriate dimension, and fit the result.
When you say 6 power law curves, do you mean the sum of 6 such curves, or do you mean you have 6 curves that you would like to fit to a single power-law curve? If you have 6 curves that you are trying to fit to a single power-law curve, then you can use the \ operator together with
[ repmat(x(:),6,1), ones(length(x)*6,1) ]
and
log([y1;y2;y3;y4;y5;y6])
... but I can never remember which argument goes on which side of the \ operator. The idea here is that log(y) should be a linear fit for x. Remember to take exp() of the second coefficient output; the first coefficient output will be the exponent for the power law (and should be negative.)
Thanks. I have 6 curves that I would like to fit to a single power-law curve.
Regards, Isa
If you have the Optimization Toolbox then you can work more accurately using one of the nonlinear least-squares routines; see http://www.mathworks.com/help/optim/nonlinear-least-squares-curve-fitting.html
I have idea about using lsqcurvefit to fit dependent and independent variables. But my present case is such that I have a number of power law curves with x(i) and y(i) (i is the number of curves). For instance, I have these three curves
x1=[0.8380 0.5400 0.3600 0.2680 0.2250 0.1930 0.1710];
y1=[0.0582 0.2328 0.5820 1.7459 3.4918 5.8197 11.6394];
x2=[0.8960 0.6040 0.4460 0.3720 0.3310 0.3030 0.2600];
y2=[0.0218 0.0870 0.2176 0.6528 1.3056 2.1759 4.3518];
x3=[0.6110 0.3740 0.2570 0.1830 0.1510 0.1290 0.1110];
y3=[0.0832 0.3328 0.8320 2.4959 4.9918 8.3196 16.6392];
I am trying to fit to a single power-law curve. I have optimization toolbox.
Thanks
Isa
allX = [x1,x2,x3,x4,x5,x6];
allY = [y1,y2,y3,y4,y5,y6];
A = [log(allX(:)), ones(length(allX),1)];
B = log(allY(:));
C = A \ B;
sortX = sort(allX);
plot(sortX, exp(C(2)) * sortX .^ C(1))
Thanks. It works

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!