A question on input and output arguments in a function, interesting.

6 vues (au cours des 30 derniers jours)
Pepe Vázquez
Pepe Vázquez le 2 Sep 2012
Hello fellows users of MATLAB. Let me state my question, I really appreciate your attention. I am programming the code of a program which represents a distillation column with controllers. As part of the global iterative process I need to stablish some functions which calculate Entalphies, Liquid Flowrates, Temperatures and Vapor compositions. My problem is that I have a function that needs as input argument a Temperature value(TBUBLE) and the expresion in the function also calculates a temperature value because the program needs it, this is an output value (TBUBLE). In your experience: Is it possible to declare a function with a name for an input argument exactly the same as the name for an output argument?, as in my case TBUBLE.
Thank you .
function [TBUBLE,YBUBLE]=BUBPT(XS,PEP,AVPP,BVPP,TBUBLE)
*
XSS=XS(1:5);
%PEPP=PEP
AVPPP=AVPP(1:5);
BVPPP=BVPP(1:5);
% LAZO=0.0;
% Initial values
SUMYTA=0.0;
FSLOPEE=0.0;
while LAZO <=50
for K=1:5
%TBUBLE IS NEEDED AS INPUT ARGUMENT
PSS(K)=exp(BVPPP(K)+AVPPP(K)/(TBUBLE+460.));
YBUBLE(K)=PSS(K)*XSS(K)/PEP;
SUMYTA=SUMYTA+YBUBLE(K);
end
if abs((SUMYTA-1.)<=0.00001)
% disp('TEMP-LAZO')
break
else
FEE=SUMYTA*PEP-PEP;
TSQQ=(TBUBLE+460.)^2;
end
for K=1:5
FSLOPEE=FSLOPEE-AVPPP(K)*XSS(K)*PSS(K)/TSQQ;
end
%TBUBLE is calculated again
TBUBLE=TBUBLE-FEE/FSLOPEE;
% Increase counting
LAZO=LAZO+1;
disp('TEMP-LAZO')
end
end
  2 commentaires
Jan
Jan le 2 Sep 2012
Modifié(e) : Jan le 2 Sep 2012
abs((SUMYTA-1.) <= 0.00001) does most likely not, what you are expecting: the ABS() is applied after the <= comparison. But the operation abs(true) or abs(false) is not really useful. Do you mean:
abs(SUMYTA-1.) <= 0.00001
Pepe Vázquez
Pepe Vázquez le 2 Sep 2012
Jan Simon, Actually, what you said is true, I didn´t notice that, thank you.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Sep 2012
Yes, it is valid to have an output argument name that is the same as an input argument name. Indeed, there are some internal optimizations that can only occur in this situation.

Plus de réponses (1)

Matt Fig
Matt Fig le 2 Sep 2012
Even a one-line function is possible in MATLAB. This is a valid function...
function num = myecho(num)

Catégories

En savoir plus sur Distillation Design 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!

Translated by