Effacer les filtres
Effacer les filtres

Failure in initial objective function evaluation. FSOLVE cannot continue

30 vues (au cours des 30 derniers jours)
Rodrigo Curvelo
Rodrigo Curvelo le 27 Juil 2018
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 commentaire
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.

Connectez-vous pour commenter.

Réponses (2)

Basil C.
Basil C. le 27 Juil 2018
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 le 9 Fév 2022
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

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by