i have a problem regarding curve fitting function

i have data like this xdata = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33]; ydata = [0.0449 0.0867 0.2376 0.3124 0.4854 0.8022 0.8441 1.1737 1.9452 2.2362 2.5294 3.2156 3.3145 3.6549 4.5624 4.8957 5.6970 5.8653 5.9630 6.8875 7.1622 8.7886 9.3904 9.7026 9.8981 12.9181 15.0099 15.2333 15.9362 20.1268 27.8382 44.6607];
i want to develop either power law or exponential law or both to the above data. how to develop the equation. cana anyone help me please...

Answers (2)

Try this:
xdata = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33];
ydata = [0.0449 0.0867 0.2376 0.3124 0.4854 0.8022 0.8441 1.1737 1.9452 2.2362 2.5294 3.2156 3.3145 3.6549 4.5624 4.8957 5.6970 5.8653 5.9630 6.8875 7.1622 8.7886 9.3904 9.7026 9.8981 12.9181 15.0099 15.2333 15.9362 20.1268 27.8382 44.6607];
pwrlawfcn = @(b,x) exp(b(2)).*x.^b(1);
NRCFPL = @(b) norm(ydata - pwrlawfcn(b,xdata));
[BPL,ResNormPL] = fminsearch(NRCFPL, [1; 10]);
expfcn = @(b,x) b(2).*exp(b(1).*x);
NRCFEF = @(b) norm(ydata - expfcn(b,xdata));
[BEF,ResNormEF] = fminsearch(NRCFEF, [1; 10]);
ResNorms = sprintf('Power Law Residual Norm\t= %.3f\nExponential Residual Norm\t= %.3f', ResNormPL, ResNormEF)
figure(1)
plot(xdata, ydata, 'pg')
hold on
plot(xdata, pwrlawfcn(BPL,xdata), '-r')
plot(xdata, expfcn(BEF,xdata), '-b')
hold off
grid
legend('Data', 'Power Law', 'Exponential', 'Location','NW')
The power law provides a slightly better fit.
This works quite well:
spl= slmengine(xdata,ydata,'knots',[0 10 20 25 30 33],'increasing','on','concaveup','on','leftvalue',0,'plot','on')
Both power law models and exponential models really don't have the shape to follow that curve, so you will significant lack of fit. Only a spline model has a chance to fit it well, so what matters is if you can use a spline, or if you really need that nonlinear model form. Much of the time, you don't need more than a spline.
Remember that a spline will give you nothing that you can simply write down, if you want a formula. It can do no more than a splendid job of fitting your data. You can use it to predict points, draw plots, etc.

Categories

Asked:

on 21 Jul 2017

Commented:

on 25 Jul 2017

Community Treasure Hunt

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

Start Hunting!