Attached is my code
yfirst=[.8967e07 1.6294e07 2.6587e07 3.2537e07 3.6136e07 3.8419e07 3.9706e07]'; xfirst=[1,2,4,6,8,10,15];[estimates, model] = myfun(xfirst,yfirst);[sse, FittedCurve] = model(estimates);semilogx(xfirst,FittedCurve,'-g*'); hold on;semilogx(xfirst,yfirst,'-rd');hold off; xlim([ 0 50 ]);%%%%FUNCTION FILE
function [estimates, model] = myfun(xdata, ydata)% Call fminsearch with guessed starting point.
% start_point =[2.23e7;.005];
model = @expfun;estimates = fminsearch(model,start_point); function [sse, FittedCurve] = expfun(params) A=params(1) lambda=params(2) FittedCurve =(A .* exp(lambda * xdata)); ErrorVector = FittedCurve - ydata; sse = sum(ErrorVector .^ 2); endend
I get a large error and the curve does not match when plotted together. Thanks
Best Answer