Fsolve, function, and adding parameters to a script outside of a function help

12 次查看(过去 30 天)
So I have my function here
function fcns = CSTReqs(w)
S = w(1);
X = w(2);
CIBAP = w(3);
CIBPE = w(4);
CH2O = w(5);
t = w(6);
Ccat = 0.78;
k1 = 1.14;
k2 = 0.095;
KIBAP = 76.4;
KH2 = 141;
KH2O = 529;
PH2 = 40;
r1 = Ccat*k1*CIBAP*PH2/(1 + KIBAP*CIBAP + (KH2*PH2)^(1/2) + KH2O*CH2O)^2;
r2 = Ccat*k2*CIBPE*PH2/(1 + KIBAP*CIBAP + (KH2*PH2)^(1/2) + KH2O*CH2O)^2;
CIBAP0=5.4;
fcns(1) = CIBAP0 - CIBAP - t*r1;
fcns(2) = -CIBPE + t*(r1 - r2);
fcns(3) = -CH2O + t*r2;
fcns(4) = S - (CIBPE/(CIBAP0-CIBAP));
fcns(5) = X - ((CIBAP0-CIBAP)/5.4);
end
And I want to solve this function by inputting X values ranging from 0 to 1 to see how all of my variables change. Ultimately I want to make a plot of X vs S.
for X=0:0.1:1
f = @(x) CSTReqs(S,X,CIBAP,CIBPE,CH2O,t);
fsolve(f,[1,1,1,1,1,1])
end
If I input an X into the function itself and use fsolve(@CSTReqs,[1,1,1,1,1,1]), I get a solution. However when I write the code above for changing X values I get
??? Undefined function or variable 'S'.
Error in ==> @(X)CSTReqs(S,X,CIBAP,CIBPE,CH2O,t)
Error in ==> fsolve at 248
fuser = feval(funfcn{3},x,varargin{:});
Error in ==> CSTR_solved at 3
fsolve(f,[1,1,1,1,1,1])
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by