Problem with if statement

조회 수: 1(최근 30일)
Francesco Renzulli 2021년 1월 13일
답변: Gaurav Garg 2021년 1월 25일
Hi in this program I take data from an excel file, interpolate them with a spline, this part of the code doesn't appear because it works. The problem here is that a certain point we should enter in the if cycle with the last value of i and start another calculation, until the index j arrives to Nt, but the program never enter in the if cycle, even if the if statement is true, I don't know why?. maybe i should choose a comlpletely different structure using while, but how can I index the variables with while ?
kind regards
Francesco Renzulli
for i=1:Nt-1
H_t_e(i) = ppval(H_ts,T(i));% ppval per valutare il polinomio
dQ(i)=m_vap(i)*H_t_e(i);
Cp_liq_e(i)=ppval(Cp_liqs,T(i));
dT(i)=(-dQ(i))/(m_liq(i)*Cp_liq_e(i));
T(i+1)=T(i)+dT(i);
rho_liq_e(i)=ppval(rho_liqs,T(i+1));
rho_vap_e(i)=ppval(rho_vaps,T(i+1));
P_tank(i)=ppval(P_vaps,T(i+1));
P_cham(i)=0.4*P_tank(i);
m_dot_liq(i)=N*A_orifice*sqrt((2*rho_liq_e(i)*(P_tank(i)-P_cham(i)))/2.0);
m_tot(i+1)=m_tot(i)-m_dot_liq(i)*dt(i);
m_liq(i+1)=m_liq(i)-m_dot_liq(i)*dt(i);
m_vap(i+1)=+m_liq(i+1)-((V_tank-(m_tot(i)/rho_vap_e(i)))/((1/rho_liq_e(i))-(1/rho_vap_e(i))));
if m_liq(i+1)>m_liq(i)
for j=i:Nt
P_tank(j)=ppval(P_vaps,T(j));
C_liq_eg(j)=ppval(Cp_liqs,T(j));
rho_vap_e(j)=ppval(rho_vaps,T(j));
Z(j)=ppval(Zs,T(j));
m_dot_vap(j)=N*A_orifice*sqrt((2*rho_vap_e(j)*(P_tank(j)-P_cham))/C_liq_eg(j));
m_vap(j+1)=m_vap(j)-m_dot_vap(j)*dt;
m_tot(j+1)=m_tot(j)-m_dot_vap(j)*dt;
Z1(j+1)=0.9*Z(j);
T1(j+1)=T(j)*(((Z1(j+1)*m_vap(j+1))/Z(j)*m_vap(j))^(gamma-1));
Z2(j+1)=(Z(j)*m_vap(j)*((T(j+1)-T(j))^(1/(gamma-1))))/m_vap(j+1);
T2(j+1)=T(j)*(((Z2(j+1)*m_vap(j+1))/Z(j)*m_vap(j))^(gamma-1));
Z3(j+1)=(Z(j)*((T(j+1)-T(j))^(1/(gamma-1))))/m_vap(j+1);
T(j+1)=T(j)*(((Z3(j+1)*m_vap(j+1))/Z(j)*m_vap(j))^(gamma-1));
end
end
end
댓글 수: 2표시숨기기 이전 댓글 수: 1
Francesco Renzulli 2021년 1월 13일
yeah beacuase it is a simulation of a tank that has vapour and liquid inside, so at a certain iteration m_liquid would become negative and so the statement shold be verified
and when it is verified, it never enters the if cycle

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

답변(1개)

Gaurav Garg 2021년 1월 25일
Hi Francesco,
The best workaround in such situations is to place a breakpoint where you feel the problem is and check all the variables and their values there.
For example, in your case, you should place a breakpoint at if m_liq(i+1)>m_liq(i) and then check the values of m_liq(i+1) and m_liq(i).
You can find out how to set breakpoints here.

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

Community Treasure Hunt

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

Start Hunting!

Translated by