How to use one ode45 to solve another?
1 view (last 30 days)
Show older comments
Carlos Ojeda
on 29 Apr 2020
Commented: David Goodmanson
on 1 May 2020
I have the following for my first ODE:
t0=0; tf=7;
y0=[0 0 0.332]';
[t,y]=ode45('ydot',[t0 tf],y0);
'ydot' is shown below:
function xdot = ydot(t,y)
xdot = zeros(3,1);
xdot(1) = y(2);
xdot(2) = y(3);
xdot(3) = -0.5*y(1)*y(3);
end
I now have a separate set of equations, where I need y from the initial solution.
function zdot = gdot(t,g)
zdot = zeros(2,1);
zdot(1) = g(2);
zdot(2) = -0.5*Pr*y(1)*g(2);
end
The second ode45 I need to solve is below.
t0=0; tf=7; Pr=0.6;
%y0=[0 0 0.332]';
%[t,y]=ode45('ydot',[t0 tf],y0);
g0=[0 0.332*Pr^(1/3)]';
[t,g]=ode45('gdot',[t0 tf],g0);
Any help is greatly appreciated.
0 Comments
Accepted Answer
David Goodmanson
on 29 Apr 2020
Edited: David Goodmanson
on 29 Apr 2020
Hi Carlos,
you can toss them all in together, with g(1) = y(4) and g(2) = y(5). That way y(1) is available in context.
t0=0; tf=7;
Pr = 0.6;
y0=[0 0 0.332 0 0.332*Pr^(1/3)]';
[t,y]=ode45(@ydotcalc,[t0 tf],y0);
fig(1)
plot(t,y);grid on
function ydot = ydotcalc(t,y)
Pr = 0.6;
ydot = zeros(5,1);
ydot(1) = y(2);
ydot(2) = y(3);
ydot(3) = -0.5*y(1)*y(3);
ydot(4) = y(5);
ydot(5) = -0.5*Pr*y(1)*y(5);
end
2 Comments
David Goodmanson
on 1 May 2020
Hi Carlos,
it looks like you might be intending
T = (((U_inf*v*x)^(1/2)*y(:,4))-T_s)/(T_inf-T_s);
figure(2)
plot(T,y(:,4));
but it's not so clear. What is the underlying equation here?
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!