Failure in initial objective function evaluation. FSOLVE cannot continue

59 次查看(过去 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
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.
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);

Alan Weiss
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

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by