Hello I am using lsqcurvefit to estimate parameters a and b. The code is working but I would like the estimated value of a>b. How can I add this constraint? I used options=(x0(2)<x0(1)); but it is not working. Any ideas? Thanks
This is the code:
function modelfitX_Data=[1,2,3,4,5,6,7,8,9,10,11];Y_Data=[33,106,95,62,147,133,150,131,150,185,144];INI=[1000,200,33];T0=1;TF=11;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Estimate parameters
xdata=X_Data;ydata=Y_Data;x0(1)=0.01; %a
x0(2)=0.1; %b
LB=[0 0];UB=[1 1];options=(x0(2)<x0(1));x=lsqcurvefit(@Model,x0,xdata,ydata,LB,UB,options)a=x(1)b=x(2)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1);hold onplot(T0+t,P,'r');plot(X_Data,Y_Data,'b*');axis([T0 TF 0 200]);hold off%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [ydot]=modelfit(t,y) S=y(1); I=y(2); R=y(3); ydot(1) = -a*y(1)-y(2); ydot(2) =a*y(1)-y(2)-b*y(2); ydot(3) = b*y(2); ydot=ydot'; end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function N=Model(x0,xdata)%set up parameters
a=x0(1);b=x0(2);[t y] = ode45(@modelfit,[0:1:TF-T0],INI);S=y(:,1);I=y(:,2);R=y(:,3);P=R;for i=1:length(xdata) ind=find(xdata(i)-T0==t); S=y(ind,1); I=y(ind,2); R=y(ind,3); N(i)=R;end end end
Best Answer