matlab ode45 out of memory

2 visualizzazioni (ultimi 30 giorni)
Mitul Dattani
Mitul Dattani il 14 Nov 2018
Commentato: madhan ravi il 15 Nov 2018
Out of memory error on line 45 cant draw the graph of the below function
function dh_dt = tankf1(t,h)
% Tank model parameters and constants
A = 12.5; % m^2
CV1 = 3.41; % (m^3/h)/kPa^0.5
CV2 = 3.41; % (m^3/h)/kPa^0.5
P0 = 100; % kPa
P3 = 100; % kPa
rho = 1000; % kg/m^3
g = 9.81; % m/s^2
P1 = P1function(t); % kPa
dh_dt = (1/A)*((CV1*sqrt(P1-P0-rho*g*h/1000))-(CV2*sqrt(P0+rho*g*h/1000-P3)));
% Set extra parameters
tf = 72; % h
h0 = 2; % m
% Solve the DAE
opts = odeset('Reltol',1e-5);
[t,h] = ode45(@tankf1,[0 tf],h0,opts);
% Plot the graph
plot(t,h)
title('Tank model solved by Method 1')
xlabel('Time (h)')
ylabel('Level (m)')
grid on
function P1 = P1function(t)
% P1FUNCTION: Upstream pressure (kPa) as a function of time (h)
if t<=10
P1 = 139.5;
elseif t<=11
P1 = 139.5 + 60.5*(t-10);
elseif t<=40
P1 = 200;
elseif t<=55
P1 = 200 - 30*(t-40)/15;
else % t>55
P1 = 170;
end
The error is given as :
Out of memory. The likely cause is an infinite recursion within the program.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Risposte (1)

madhan ravi
madhan ravi il 14 Nov 2018
Modificato: madhan ravi il 14 Nov 2018
tf = 72; % h
h0 = 2; % m
% Solve the DAE
opts = odeset('Reltol',1e-5);
[t,h] = ode45(@tankf1,[0 tf],h0,opts);
% Plot the graph
plot(t,h)
title('Tank model solved by Method 1')
xlabel('Time (h)')
ylabel('Level (m)')
grid on
function dh_dt = tankf1(t,h)
% Tank model parameters and constants
A = 12.5; % m^2
CV1 = 3.41; % (m^3/h)/kPa^0.5
CV2 = 3.41; % (m^3/h)/kPa^0.5
P0 = 100; % kPa
P3 = 100; % kPa
rho = 1000; % kg/m^3
g = 9.81; % m/s^2
P1 = P1function(t); % kPa
dh_dt = (1/A)*((CV1*sqrt(P1-P0-rho*g*h/1000))-(CV2*sqrt(P0+rho*g*h/1000-P3)));
% Set extra parameters
end
function P1 = P1function(t)
% P1FUNCTION: Upstream pressure (kPa) as a function of time (h)
if t<=10
P1 = 139.5;
elseif t<=11
P1 = 139.5 + 60.5*(t-10);
elseif t<=40
P1 = 200;
elseif t<=55
P1 = 200 - 30*(t-40)/15;
else % t>55
P1 = 170;
end
end
Screen Shot 2018-11-14 at 9.32.53 PM.png
  1 Commento
madhan ravi
madhan ravi il 15 Nov 2018
If it's what you were looking for make sure to accept the answer else let know.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by