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

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

Jan
Jan 2012년 9월 2일
편집: Jan 2012년 9월 2일
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
Jan Simon, Actually, what you said is true, I didn´t notice that, thank you.

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

 채택된 답변

Walter Roberson
Walter Roberson 2012년 9월 2일

0 개 추천

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.

추가 답변 (1개)

Matt Fig
Matt Fig 2012년 9월 2일
Even a one-line function is possible in MATLAB. This is a valid function...
function num = myecho(num)

카테고리

도움말 센터File Exchange에서 Distillation Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by