Debugging help needed: ODEs returning NaN
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi! I'm trying to debug my code. I can't figure out what's causing my ODEs to return NaN. Y(:,2) and Y(:,3) have the initial condition for the first entry, and NaN for every other entry. I set the debugger to stop if NaN/Inf is encountered but I still can't figure out what the problem is. My code is as follows:
k1=0.05; %L/mol/min
k2=0.25; %L/mol/min
tbar=75; %min
cAo=0.6; %mol/L
cBo=0.4; %mol/L
Et=@(t)4*t*exp(-2*t/tbar)/tbar^2;
cCt=@(y)4/3.*(cAo-y(2))-2/3.*(cBo-y(3));
concs=@(t,y)[-Et(t);
-(k1*y(2)*y(3)+Et(t)/y(1)*(y(2)-cAo));
-(k1*y(2)*y(3)+k2*y(3)*cCt(y)+Et(t)/y(1)*(y(3)-cBo))];
[T,Y] = ode45(concs,[10*tbar 0],[0 1 0.343]);
Any help would be much appreciated. Thanks!
0 commentaires
Réponse acceptée
Andrew Newell
le 17 Fév 2011
The short answer is that your problem is ill-conditioned, as you'll see from the messages if you use ode23s in place of ode45. You could try debugging this by putting the function CONCS in a separate file so you can set break points.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!