Exponential Curve fitting
이전 댓글 표시
Hello,
I am fairly new to Matlab and have been teaching myself for a few months. I have written a code to curve fit some data and calculate time and rate constants for the exponential recovery for some data. I have been running into some problems curve fitting the data, and I cannot figure out where the problem is. The code will fit some data, and have issues with others. Any help would be great! Below, I will post the curve fitting function code, and also the data I am trying to fit.
Thanks in Advance!!!!
Here is the Curve Fitting Function:
function [estimates, model] = curvefit(xdata, ydata)
% fits data to the curve y(x)=A-B*e(-lambda*x))
start_point = [1,1,1];
model =@efun;
estimates = fminsearch(model, start_point);
% expfun accepts curve parameters as inputs, and outputs sse,
% the sum of squares error for A -B* exp(-lambda * xdata) - ydata,
% and the FittedCurve.
function [sse,FittedCurve] = efun(v)
A=v(1);
B=v(2);
lambda=v(3);
FittedCurve =A - B*exp(-lambda*xdata);
ErrorVector=FittedCurve-ydata;
sse = sum(ErrorVector .^2);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Here is some data I am trying to fit with this code
xdata=[0;10.7;21.2;31.7;41.9;52.2;62.6;72.6;82.9;92.9;103.2;113.2;123.5;133.8;144;154.3;164.9;175.2;185.5;196;206.9;217.2;227.4;237.7;248.3];
ydata=[-2.5808;-2.1815;-1.6986;-1.2984;-0.9516;-0.7136;-0.4505;-0.3751;-0.3165;-0.2603;-0.2263;-0.1996;-0.1658;-0.1983;-0.2140;-0.2365;-0.1680;-0.1751;-0.1757;-0.1827;-0.1968;-0.1811;-0.1550;-0.1901;-0.1510];
댓글 수: 1
the cyclist
2011년 10월 3일
Can you be more specific about what you mean by "have issues with other [data]"? MATLAB throws an error? The fit is not as good as you think it should be? Be as specific as you can.
채택된 답변
추가 답변 (1개)
the cyclist
2011년 10월 3일
I think a more stringent tolerance for the fit will get you what you want. Use these lines in place of your call to fminsearch:
options = optimset('Display','iter','TolFun',1e-16);
estimates = fminsearch(model, start_point,options);
카테고리
도움말 센터 및 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!