ODE45 error must return column vector
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Brianna Biondo
le 11 Mar 2023
Commenté : Walter Roberson
le 11 Mar 2023
No matter what I do I keep receiving the error of a column vector. I have tried making it all zeros first befort completing the function to create a column vector but nothing is working. Any insight would be helpful.
CO(2,1) = 10;
tRange(2,1) = 10;
[tSol,CSol] = ode45(@ConvFunction,tRange,CO);
plot(tSol,CSol(:,1))
function F = ConvFunction(t,~)
CaO=10;
k1=.45;
k2=.05;
Ca=CaO*exp(-t*(k1+k2));
dCadt=-(k1*(Ca)-(k2*(Ca)));
dCbdt=k1*(Ca);
dCcdt=k2*(Ca);
dFdt = zeros(3,1);
dFdt = [dCadt dCbdt dCcdt];
F= dFdt;
end
0 commentaires
Réponse acceptée
Paul
le 11 Mar 2023
Try doing what the error message says and make sure that F is a column vector. Here's one option
dFdt = [dCadt ; dCbdt ; dCcdt];
Also, the code is only specifying two initial conditions. It needs to specify three.
2 commentaires
Brianna Biondo
le 11 Mar 2023
Modifié(e) : Brianna Biondo
le 11 Mar 2023
Walter Roberson
le 11 Mar 2023
Unless you have assigned something to CO before this,
CO(2,1) = 10;
creates CO as a column vector with exactly two values. You are passing that vector of length 2 as the initial state. You ignore the state inside ConvFunction and return a vector of length 3 . The length of the vector you return must be the same as the number of input values.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!