% Estimacao de parametros nao-lineares

dados =[...
0  0
1  0.058
2  0.217
3  0.36
4  0.488
5  0.6
6  0.692
7  0.772
8  0.833
9  0.888
10 0.925];

t = dados(:,1);
y_k = dados(:,2);

clf
plot(t,y_k,'o'), title('dados experimentais');
xlabel('t'); ylabel('y(t)'); figure(gcf), pause

%
% modelo: f(t)_k = 1 - (a1 * exp(-t/a1) - a2 * exp (-t/a2))/(a1-a2)
%

a = [1 0.5]';

v=version;
if v(1) > '4',
OPTIONS=optimset('LargeScale','on','Display','iter','LineSearchType','cubicpoly','TolX',1e-6,'TolFun',1e-6);
% OPTIONS=optimset('LargeScale','off','Display','iter','LevenbergMarquardt','on','LineSearchType','cubicpoly','TolX',1e-6,'TolFun',1e-6);
% OPTIONS=optimset('LargeScale','off','Display','iter','Algorithm','levenberg-marquardt','LineSearchType','cubicpoly','TolX',1e-6,'TolFun',1e-6); 
% OPTIONS=optimset('LargeScale','off','Display','iter','Levenberg-Marquardt','on','LineSearchType','cubicpoly','TolX',1e-6,'TolFun',1e-6);
% OPTIONS=optimset('LargeScale','on','Display','iter');
 [a,nres,res,eflag,out]=lsqnonlin('modelo',a,[],[],OPTIONS,dados);
else
 OPTIONS=foptions;
 [a,OPTIONS,res]=leastsq('modelo',a,OPTIONS,[],dados);
end

disp('parametros do modelo:'); a
e=modelo(a,dados);

plot(t,y_k-e,t,y_k,'o'), title('modelo x dados');
xlabel('t'); ylabel('y(t)'); legend('dados','modelo'); figure(gcf);

