lsqcurvefit help: Function value and YDATA sizes are not equal.

조회 수: 4 (최근 30일)
Fiona Chandra
Fiona Chandra 2019년 4월 11일
댓글: Fiona Chandra 2019년 4월 11일
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';
end
end

채택된 답변

Matt J
Matt J 2019년 4월 11일
[fitpars, resnorm] = lsqcurvefit(@PO_PK2comp,par0,tdata,ydata.');
  댓글 수: 1
Fiona Chandra
Fiona Chandra 2019년 4월 11일
Thank you, tht works! Tried ' before on both tdata and ydata, didn't realize it should just be on ydata

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Functional Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by