How can I output intermediate vaviables when using ode45 funcion?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to output an intermediate vaviable when using ode45 funcion.In the following codes, a_k is the function of w, I want to output the value of a_k at every step, which is [-110:1:115],and plot(w,a_k). Is there any way to solve the problem? Thank you all!
function main
CA_span= -110:1:115;
Qf0=0;
mf0=0.005;
m0=2.5;
y0=[Qf0 mf0 m0];
[T,Y]=ode45(@hrr_ode1,CA_span,y0);
end
function dy=hrr_ode1(w,y)
T=p(w)*Vz(w)/(y(3)*R);
a_k=(y(3)-y(2))/(L0*y(2));
% a_k is the function of w, I want to output the value of a_k at every step, which is [-110:1:115]
x1=0.001*p(w)*dVzdw(w);
x2=dQ0dw(T,p(w),w);
x3=(1/(R/1000))*C_v(T,a_k)*(Vz(w)*dpdfai(w)+p(w)*dVzdw(w))*0.001;
x4=U(T,a_k);
x5=C_v(T,a_k)*T;
x6=y(3)*U_ak(T,a_k)*a_k/y(2);
dy=zeros(3,1);
if w<0
dy(1)=0;
dy(2)=0;
dy(3)=0;
else
dy(1)=(x1+x2+x3)/(1-(1/Hu)*(x4-x5-x6));
dy(2)=max( dy(1)/Hu,0);
dy(3)=max( dy(1)/Hu,0);
end
end
0 commentaires
Réponse acceptée
Grzegorz Knor
le 16 Juil 2013
You can use OutputFcn to do this. Just add options to ode45 in this way:
options = odeset('OutputFcn',@myfun);
[T,Y]=ode45(@hrr_ode1,CA_span,y0);
And define myfun as:
function status = myfun(t,y,flag)
.
.
.
switch(flag)
case 'init'
.
.
.
case 'done'
.
.
.
end
end
status = 0;
You have to fill dots in the code above with proper commands.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!