what is the error "must return a column vector."

조회 수: 4 (최근 30일)
jaeug choi
jaeug choi 2020년 5월 25일
댓글: Star Strider 2020년 5월 25일
function dydt = rhs5(~,y,I)
ksyn=0.025;
kdeg1=0.25;
kdeg2=0.01;
kCdc_plus=3;
kCdc_minus=1.5;
kP_plus=1;
kP_minus=0.5;
Kmd=0.02;
Kmc=0.5;
Km1=0.005;
Km2=0.005;
Km3=0.005;
Km4=0.005;
dydt=zeros(1,1);
dydt(I.C)=ksyn-kdeg1*y(I.P)*y(I.C)/(Kmd+y(I.C))-kdeg2*y(I.C);
dydt(I.Cdc)=(kCdc_plus)*(y(I.C)/(Kmc+y(I.C)))*((1-y(I.Cdc))/(Km1+(1-y(I.Cdc))))-(kCdc_minus)*(y(I.Cdc)/(Km2+y(I.Cdc)));
dydt(I.P)=(kP_plus)*y(I.Cdc)*((1-y(I.P))/(Km3+(1-y(I.P))))-(kP_minus)*(y(I.P)/Km4+y(I.P));
end
[times,ys] = ode45(@(t,y)rhs5(t,y,I),tspan,y0,options);
Error using odearguments (line 93)
@(T,Y)RHS5(T,Y,I) must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
why the error happened to my code??

답변 (1개)

Star Strider
Star Strider 2020년 5월 25일
The ODE function must return a column vector. I have no idea what ‘I’ is, however defining it as I do here, the code runs without error.
Try this:
function dydt = rhs5(~,y,I)
ksyn=0.025;
kdeg1=0.25;
kdeg2=0.01;
kCdc_plus=3;
kCdc_minus=1.5;
kP_plus=1;
kP_minus=0.5;
Kmd=0.02;
Kmc=0.5;
Km1=0.005;
Km2=0.005;
Km3=0.005;
Km4=0.005;
dydt=zeros(3,1);
dydt(I.C)=ksyn-kdeg1*y(I.P)*y(I.C)/(Kmd+y(I.C))-kdeg2*y(I.C);
dydt(I.Cdc)=(kCdc_plus)*(y(I.C)/(Kmc+y(I.C)))*((1-y(I.Cdc))/(Km1+(1-y(I.Cdc))))-(kCdc_minus)*(y(I.Cdc)/(Km2+y(I.Cdc)));
dydt(I.P)=(kP_plus)*y(I.Cdc)*((1-y(I.P))/(Km3+(1-y(I.P))))-(kP_minus)*(y(I.P)/Km4+y(I.P));
end
I = struct('C',1, 'Cdc',2, 'P',3); % Create ‘I’
tspan = linspace(0, 1, 10);
y0 = rand(3,1);
[times,ys] = ode45(@(t,y)rhs5(t,y,I),tspan,y0);
figure
plot(times, ys)
grid
legend(fieldnames(I))
.
  댓글 수: 2
jaeug choi
jaeug choi 2020년 5월 25일
ahhh! I forgot to fix zeros 1 to 3..!! thanks!
Star Strider
Star Strider 2020년 5월 25일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by