Failure in initial objective function evaluation. FSOLVE cannot continue
14 ビュー (過去 30 日間)
古いコメントを表示
Hello, I'm trying to solve a non-linear system with fsolve and getting this error: " Failure in initial objective function evaluation. FSOLVE cannot continue". I tried looking for previously posts about this issue but without success. The main code is:
options = optimset('MaxFunEvals',1000,'TolFun',1e-8,'Display','off');
x0 = [300 1];
x = fsolve(@(x)lista1b_fct(x),x0,options)
and the function is:
parametros
function res = lista1b_fct(x)
Tee = x(1);
Cee = x(2);
res(1) = q*Cf - q*Cee - V*k0*Cee*exp(-E/(R*Tee));
res(2) = q*cp*(Tf - Tee) + deltaH*V*k0*Cee*exp(-E/(R*Tee)) - hA*(Tee - Tc);
end
1 件のコメント
Declan Oberbreckling-Schmitt
2022 年 2 月 7 日
Try putting 'res' in brackets so that it's like:
function [res] = listsa1b_fct(x)
If that doesn't work, trying using a different variable name than res. It worked for me. I have no idea why.
回答 (2 件)
Basil C.
2018 年 7 月 27 日
I guess the mistake you are making is in using
Tee = x(1);
Cee = x(2);
Rather it should be
Tee = x0(1);
Cee = x0(2);
0 件のコメント
Alan Weiss
2022 年 2 月 9 日
I think that you are missing parameters:
function res = lista1b_fct(x)
Tee = x(1);
Cee = x(2);
res(1) = q*Cf - q*Cee - V*k0*Cee*exp(-E/(R*Tee));
res(2) = q*cp*(Tf - Tee) + deltaH*V*k0*Cee*exp(-E/(R*Tee)) - hA*(Tee - Tc);
end
What is q? What is Cf? What is Cee? Etc. You have a lot of parameters that you need to pass to the function. For documentation on this subject, see Passing Extra Parameters.
One way to do so is to use a structure such as the following in your workspace before you call your function:
params.q = q; % I assume that you have a variable q in your workspace
params.Cf = Cf; % etc.
Then rewrite your function as follows:
function res = lista1b_fct(x,params)
q = params.q;
Cf = params.Cf; % etc
% And so on. Then:
Tee = x(1);
Cee = x(2);
res(1) = q*Cf - q*Cee - V*k0*Cee*exp(-E/(R*Tee));
res(2) = q*cp*(Tf - Tee) + deltaH*V*k0*Cee*exp(-E/(R*Tee)) - hA*(Tee - Tc);
end
Your workspace should call fsolve like this:
[x,fval,exitflag,output] = fsolve(@(x)lista1b_fct(x,params),x0,options)
Alan Weiss
MATLAB mathematical toolbox documentation
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!