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);endF=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.

## Best Answer