Error: Not enough input arguments
이전 댓글 표시
I'm trying to write a function which uses global variables this way:
function F=phi(P)
global Tc Pc T omega equation
[Z,A,B,~,~]=CompressibilityFactor(equation,Tc,Pc,omega,T,P);
ZL=Z(3);
ZV=Z(1);
if equation=="vdw"
logphiL=ZL-1-A/ZL-log(ZL-B);
logphiV=ZV-1-A/ZV-log(ZV-B);
elseif equation=="rk"
logphiL=ZL-1-A/B*log((ZL+B)/ZL)-log(ZL-B);
logphiV=ZV-1-A/B*log((ZV+B)/ZV)-log(ZV-B);
elseif equation=="rks"
logphiL=ZL-1-A/B*log((ZL+B)/ZL)-log(ZL-B);
logphiV=ZV-1-A/B*log((ZV+B)/ZV)-log(ZV-B);
elseif equation=="pr"
logphiL=ZL-1-A/(2*sqrt(2)*B)*log((ZL+B*(1+sqrt(2)))/ZL+B*(1-sqrt(2)))-log(ZL-B);
logphiV=ZV-1-A/(2*sqrt(2)*B)*log((ZV+B*(1+sqrt(2)))/ZV+B*(1-sqrt(2)))-log(ZV-B);
end
F=logphiL/logphiV-1;
end
CompressibilityFactor is another function and I know it works. When I define the global viariables with a script and then run this function I get this error
Error in phi (line 4)
[Z,A,B,~,~]=CompressibilityFactor(equation,Tc,Pc,omega,T,P);
I can't understand why.
댓글 수: 8
Alex Mcaulley
2019년 3월 19일
편집: Alex Mcaulley
2019년 3월 19일
CompressibilityFactor function is needed. By the way, more input parameters are needed in this function.
Stephen23
2019년 3월 19일
Note that global variables are the cause of many beginners problems, they are slow, buggy, and hard to debug. You should avoid using them:
Enrico Bussetti
2019년 3월 19일
You've told us the line that cause the error, but not what the error is. Please give us the full text of the error message (everything that is red).
Why do the variables have to be global? Why can't they be input arguments of phi (just as they are inputs of CompressibilityFactor. Tracking the state of global variables is difficult and becomes more so as the code grows in complexity. As Stephen said, globals are the source of many problems.
Enrico Bussetti
2019년 3월 19일
편집: Enrico Bussetti
2019년 3월 19일
Alex Mcaulley
2019년 3월 19일
Are you sure that this is the function that you are calling? I mean: Do you have more functions with the same name(older versions) in another folder? Is the following line giving the folder you are expecting?
which CompressibilityFactor
For sure, global variables are not a good idea
Enrico Bussetti
2019년 3월 19일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!