IF condition for infinity values
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Remston Martis
le 25 Avr 2018
Commenté : Remston Martis
le 25 Avr 2018
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
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!