Failure in initial objective function evaluation. FSOLVE cannot continue
59 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Declan Oberbreckling-Schmitt
el 7 de Feb. de 2022
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.
Respuestas (2)
Basil C.
el 27 de Jul. de 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);
0 comentarios
Alan Weiss
el 9 de Feb. de 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
0 comentarios
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!