IF condition for infinity values

조회 수: 9 (최근 30일)
Remston Martis
Remston Martis 2018년 4월 25일
댓글: Remston Martis 2018년 4월 25일
For the code below, sometimes the values of 'steadystate' == Infinity or NaN. How do I check this condition and display an error message? I have not posted my whole code. Initial guess councoutGuess=[0.1;0.1;0.1;0.1] initial steadystate values = [ 0.1504734, -0.049281077, 0.14977213, 0.34987724]
while abs(steadystate-concoutGuess)>Error %Convergence error criteria for the Newton Rhapson loop
bigmatrix=alt_bigmatrix; %Using the stored symbolic matrix for the loop calculations
concoutGuess=steadystate; %Updating values
concout=steadystate;
fA= ((flowinA*concinA-flowout*concout(1))/Vol) - k1*concout(1)*concout(2); %Recalcualting values similar to previous calculations
fB= ((flowinB*concinB-flowout*concout(2))/Vol) - k1*concout(1)*concout(2) - k2*concout(2)*concout(3);
fC= ((-flowout*concout(3))/Vol) + k1*concout(1)*concout(2) - k2*concout(2)*concout(3);
fD= ((-flowout*concout(4))/Vol) + k1*concout(2)*concout(3);
molflow = [ fA; fB; fC; fD ];
bigmatrix= subs(bigmatrix); %Substituting updated values and calculating in symbolic form
differential=inv(bigmatrix);
differential=vpa(differential,8);%Evaluating symbolic and rounding to specified significant figures
molflow=vpa(molflow,8);
steadystate = concoutGuess - (differential*molflow); %Newton Rhapson formula for steady state
steadystate = vpa(steadystate,8);
fprintf('%15.10g %15.10f %15.10f %15.10f %15.10f\n',count,steadystate(1),steadystate(2),steadystate(3),steadystate(4))
steadyStateMatrix(:, count) = steadystate;% storing iterations as a matirx, steadystate is a column vector
count = count + 1;
end

채택된 답변

Fangjun Jiang
Fangjun Jiang 2018년 4월 25일
isnan()
isfinite()

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by