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
Pepe Vázquez
Pepe Vázquez 2012 年 9 月 2 日
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 件のコメント

Pepe Vázquez
Pepe Vázquez 2012 年 9 月 2 日
Ok, Thank you I appreciate your answer.

サインインしてコメントする。

その他の回答 (1 件)

Matt Fig
Matt Fig 2012 年 9 月 2 日

0 投票

Even a one-line function is possible in MATLAB. This is a valid function...
function num = myecho(num)

1 件のコメント

Pepe Vázquez
Pepe Vázquez 2012 年 9 月 2 日
Ok, Thank you I appreciate your answer.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by