필터 지우기
필터 지우기

ode45 returning Nan values

조회 수: 3 (최근 30일)
Nishant Gupta
Nishant Gupta 2020년 8월 1일
댓글: Nishant Gupta 2020년 8월 4일
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!

답변 (1개)

Alan Stevens
Alan Stevens 2020년 8월 1일
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
Alan Stevens
Alan Stevens 2020년 8월 2일
편집: Alan Stevens 2020년 8월 2일
Ok. What about in dydt(1)?
Do you expect the temperatures to increase or decrease?
Nishant Gupta
Nishant Gupta 2020년 8월 4일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by