what is the error "must return a column vector."
Afficher commentaires plus anciens
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??
Réponses (1)
Star Strider
le 25 Mai 2020
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 commentaires
jaeug choi
le 25 Mai 2020
Star Strider
le 25 Mai 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!