Logarithmic Curve Fitting without use of functions
20 次查看(过去 30 天)
显示 更早的评论
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 个评论
Salaheddin Hosseinzadeh
2014-3-11
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!
采纳的回答
Star Strider
2014-3-11
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!