Logarithmic Curve Fitting without use of functions
8 views (last 30 days)
Show older comments
I have the logarithmic fit equation f(fit) = log(a1 + a2*x) and need to apply it to some data without using the fit function. So far I have come up with:
phi =[ones(size(xx)),(xx)];
aa=phi\exp(yy);
yfit =log(phi*aa);
plot(xx, yy, '', xx, yfit, 'r-')
But it does not come out with the correct fit when plotted. Can anyone see where I am going wrong?
Thanks
2 Comments
Salaheddin Hosseinzadeh
on 11 Mar 2014
Is it like you have a set of data and you want to find a1 and a2 as such that f(x)=log(a1+a2*x) fit the set of data?! If so? then what's the data!
Accepted Answer
Star Strider
on 11 Mar 2014
It took some experimenting to understand what you are doing and what your data were and how they were generated. You didn’t post the results were that you were getting (the aa coefficients you were calculating were -62E+69 and 83E+66), but assuming I got your xx and yy vectors correct, see if this code produces the result you want:
xx = [52 136 219 300 382 463 544 630 ... 2386];
yy = [3.4051 4.5940 7.9954 10.7201 14.6408 18.3000 21.4829 24.9677 ... 165.6450];
xx = xx';
yy = yy';
phi = [ones(size(xx)),(xx)];
aa = phi\log(yy);
yfit = exp(phi*aa);
figure(1)
plot(xx,yy,'.b', xx,yfit,'r-')
grid
(Row vectors take up fewer lines in the Editor.)
This produces aa coefficients of 2 and 1.5E-3, and an acceptable fit.
Your theory seems correct to me, but your data don’t appear to match your model.
When all else fails, experiment! Consider:
yy2 = log(3 + 5*xx);
aa2 = phi\exp(yy2);
yfit2 = log(phi*aa2);
figure(2)
plot(xx,yy2,'.b', xx,yfit2,'-r')
grid
That works as you intended it to.
0 Comments
More Answers (0)
See Also
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!