Error: Not enough input arguments
Show older comments
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 Comments
Alex Mcaulley
on 19 Mar 2019
Edited: Alex Mcaulley
on 19 Mar 2019
CompressibilityFactor function is needed. By the way, more input parameters are needed in this function.
Stephen23
on 19 Mar 2019
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
on 19 Mar 2019
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
on 19 Mar 2019
Edited: Enrico Bussetti
on 19 Mar 2019
Alex Mcaulley
on 19 Mar 2019
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
on 19 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!