Clear Filters
Clear Filters

Function requires more inputs

1 view (last 30 days)
Matthew Tom
Matthew Tom on 26 May 2018
Answered: Walter Roberson on 26 May 2018
Hi! I am trying to work the following code, but it keeps saying that I need more inputs:
function r = rxnrate(F)
global k Keq
Fa=F(1);
Fb=F(2);
Fc=F(3);
Fd=F(4);
f=33.3;
P=1;
Pa=(Fa/f)*P;
Pb=(Fb/f)*P;
Pc=(Fc/f)*P;
Pd=(Fd/f)*P;
r(1)=k*((Pa*Pb)-(Pc*Pd/Keq));
r(2)=k*((Pa*Pb)-(Pc*Pd/Keq));
r(3)=k*((Pa*Pb)-(Pc*Pd/Keq));
r(4)=k*((Pa*Pb)-(Pc*Pd/Keq));
r=r';
end

Answers (1)

Walter Roberson
Walter Roberson on 26 May 2018
To run that code, you need to have first executed some code that used
global k Keq
and then assigned values to k and Keq.
That having been done once, you need to invoke the routine passing in data, such as
ftest = randn(1,4);
result = rxnrate(ftest);
It is not possible to invoke the code by simply typing the name of the function, or by simply pressing the green Run button while you are in the editor on this function. Even if you have defined F in your current workspace, MATLAB will not look for an F in the hierarchy if you try to invoke rxnrate without passing in anything.

Categories

Find more on Get Started with MATLAB 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!