필터 지우기
필터 지우기

Failure in initial objective function evaluation. FSOLVE cannot continue

조회 수: 30 (최근 30일)
Rodrigo Curvelo
Rodrigo Curvelo 2018년 7월 27일
답변: Alan Weiss 2022년 2월 9일
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
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.
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에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by