Hi all,
Just learning ODE fitting with Matlab and thought I followed the directions in Monod Kinetics but I'm running into an error that I cannot pinpoint. Would love any insight as to where my error is.
Just trying to fit a simple PK equation and I keep getting:
Error using lsqcurvefit (line 262)
Function value and YDATA sizes are not equal.
Matlab code below:
———–
tdata=[0.25 0.5 1 2 4 6 8 24]; ydata=[0.1 0.5 1.19 2.2 2.8 2.2 2.17 .4];par0=[1 0.5 1 1 1 1]';[fitpars, resnorm] = lsqcurvefit(@PO_PK2comp,par0,tdata,ydata);function yout=PO_PK2comp(params,tdata)Dose=10;x0=[Dose 0 0]';[tvec,yvec]=ode45(@(t,y) PO_PK2compODE(t,y,params),tdata,x0);yout=yvec(:,2);function dy = PO_PK2compODE(t,y,params)ka=params(1);F=params(2);CL1=params(3);CL2=params(4);V1=params(5);V2=params(6);dy(1)=-ka*y(1);dy(2)=F*ka*y(1)-CL1*y(2)/V1-CL2*(y(2)/V1-y(3)/V2);dy(3)=CL2*(y(2)/V1-y(3)/V2);dy=dy';endend
Best Answer