ode45 output

2 views (last 30 days)
Erik Mele
Erik Mele on 10 Feb 2012
Edited: Hongyang on 18 Oct 2013
Hi, I'm having trouble getting a list of values from my function.
function dT=odefun(t,T)
global T1 ...etc
... etc
T2=T1*((P2/P1)^n_ex);
dT=zeros(3,1);
dT(1)=...etc
T1=T2;
How can I get ode45 to return a list of all calculated values for T1, as for dT(3,1) and not just the last value?
Thank you
  2 Comments
Andrew Newell
Andrew Newell on 10 Feb 2012
I strongly suspect that you have written odefun incorrectly. You are using a global variable to make each evaluation dependent on the previous one, which is not good practice. If you could add a description of your problem to your question, we might be able to help you sort it out.
Erik Mele
Erik Mele on 21 Feb 2012
Thank you, I realize that I was using ode45 incorrectly. I am having trouble with a heat and mass transfer problem, where I have 3 differential equations I need to solve, as well as other equations dependent on the differential equations.
Instead of writing the other equations inside ode45, is it possible to create a for loop, and repeatedly using ode45 inside?
My code is now
for i=1:x
P(i+1)=(1+(0.5/x)*i)*10^5; %Pa%
Tny(i)=T_g(i)*((P(i+1)/P(i))^n_ex);
P2=P(i+1);
T2=Tny(i);
Y2=Y(i);
j=(i-1)*(time/x);
k=(i)*(time/x);
tspan=[j k];
Ti=[m_l(i) D(i) T_l(i)];
[t T]=ode45(@odefun3,tspan,Ti);
len=size(T)
m_l(i+1)=T(len(1),1);
D(i+1)=T(len(1),2);
T_l(i+1)=T(len(1),3);
T_g(i+1)=Tny(i)+(m_l(i+1)-m_l(i))*(h_ev/M)*(1/(cp_air*m_g(i)));
%Gas temperature%
m_g(i+1)=m_g(i)+(m_l(i+1)-m_l(i))*(time/x);
m_s(i+1)=m_s(i)+(m_l(i+1)-m_l(i))*(time/x); %Total steam mass%
Y(i+1)=(((m_s(i)+(m_l(i+1)-m_l(i)))/Mv)/((m_g(i)+(m_l(i+1)-m_l(i)))/M)); %Mole fraction vapor%
end
Y2 T2 and P2 are now global variables used inside ode45. I am concerned with the use of j and k, are theese time variables correct inputs for the ode45 equation?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!