Borrar filtros
Borrar filtros

ode45 returning Nan values

3 visualizaciones (últimos 30 días)
Nishant Gupta
Nishant Gupta el 1 de Ag. de 2020
Comentada: Nishant Gupta el 4 de Ag. de 2020
Iam trying to solve a system of differential equations using the ode45 command. However I am only getting Nan values as the output. Here's the code I have so far-
clc
global rho Cp MW dH
tspan = 60*[1 300000];
y0 = [1 333.15];
[t, y] = ode45(@myODE, tspan, y0)
plot(t/60, y(:,2)-273.15)
function dydt = myODE(t, y)
rho = 906;
Cp = 0.4365;
MW = 104.15;
dH = -17800;
y2 = 1-y(1);
A0 = 1.964*(10^5)*exp(-10040/y(2));
A1 = 2.57-5.05*y(2)*(10^(-3));
A2 = 9.56-1.76*y(2)*(10^(-2));
A3 = -3.03+7.85*y(2)*(10^(-3));
A = A0*exp(A1*(y2) + A2*(y2^2) + A3*(y2^3));
dydt = zeros(2,1);
dydt(1) = -A*((rho*y(1)/MW)^(1.5))*y(1);
dydt(2) = (dH/(Cp*MW))*(-A*((rho*y(1)/MW)^(1.5))*y(1));
end
This is the output I get-
y =
1.0e+02 *
0.0100 + 0.0000i 3.3315 + 0.0000i
NaN + NaNi NaN + NaNi
NaN + NaNi NaN + NaNi
NaN + NaNi NaN + NaNi
I am not sure where I am going wrong here. Is there a problem with the equations? Any help is appreciated!

Respuestas (1)

Alan Stevens
Alan Stevens el 1 de Ag. de 2020
Have you basically got the wrong sign in dydt(2)?
tspan = 60*[1 300000];
y0 = [1 333.15];
[t, y] = ode45(@myODE, tspan, y0);
plot(t/60, y(:,2)-273.15)
function dydt = myODE(~, y)
rho = 906;
Cp = 0.4365;
MW = 104.15;
dH = -17800;
y2 = 1-y(1);
A0 = 1.964*(10^5)*exp(-10040/y(2));
A1 = 2.57-5.05*y(2)*(10^(-3));
A2 = 9.56-1.76*y(2)*(10^(-2));
A3 = -3.03+7.85*y(2)*(10^(-3));
A = A0*exp(A1*(y2) + A2*(y2^2) + A3*(y2^3));
dydt = zeros(2,1);
dydt(1) = -A*((rho*y(1)/MW)^(1.5))*y(1);
dydt(2) = (dH/(Cp*MW))*(A*((rho*y(1)/MW)^(1.5))*y(1)); % Changed the sign from -A to +A
end
  3 comentarios
Alan Stevens
Alan Stevens el 2 de Ag. de 2020
Editada: Alan Stevens el 2 de Ag. de 2020
Ok. What about in dydt(1)?
Do you expect the temperatures to increase or decrease?
Nishant Gupta
Nishant Gupta el 4 de Ag. de 2020
I expect the temperature to increase. As dH is negative, heat will be evolved as the reaction proceeds. y(1) is the mole fraction and y(2) is the temp.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by