Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
Show older comments
Hi,
by executing the following code, I get the error message:
An error occurred while running the simulation and the simulation was terminated
Error evaluating registered method 'Outputs' of MATLAB S-Function 'potential_field' in 'model_4WID/Level-2 MATLAB S-Function'. The following is the MATLAB call stack (file names and line numbers) that produced this error:
['C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\shared\optimlib\optimfcnchk.p'] [317]
['C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\shared\optimlib\fmincon.p'] [534]
['C:\Users\Valéry EBOGO\Documents\MATLAB\potential_field.m'] [113]
User function '@(X)(a0*(u(6)-X(1))^2+av*(X(1)*tan(X(2))-u(10))^2+Urep_1+Urep_2+c*(X(2)-u(3))^2)' returned NaN when evaluated;
FMINCON cannot continue.
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
when I evaluate the objective function in X0, J=0*(0-0) ~=NAN.
moreover, by changing the algorithm(sqp or inerior-point) the result is the same. And when i set "Funvalcheck" to 'off', this message appears: "Objective function is undefined at initial point. Fmincon cannot continue."
all my attempts to solve this problem have so far been unsuccessful.
i really need your help!!!!
Thank you in advance.
function potential_field(block)
setup(block);
end
function setup(block)
% Register number of ports
block.NumInputPorts = 1;
block.NumOutputPorts = 1;
% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;
%% Override input port properties----------------------------------------
block.InputPort(1).DatatypeID = 0; % double
block.InputPort(1).Complexity = 'Real';
block.InputPort(1).Dimensions = 10;
block.InputPort(1).DirectFeedthrough = false;
%% Override output port properties---------------------------------------
block.OutputPort(1).DatatypeID = 0; % double
block.OutputPort(1).Complexity = 'Real';
block.OutputPort(1).Dimensions = 6;
% Register the parameters.
block.NumDialogPrms = 0;
% Set up the continuous states.
block.NumContStates = 0;
block.SampleTimes = [0 0];
block.SetAccelRunOnTLC(false);
block.SimStateCompliance = 'DefaultSimState';
% sample-based mode=mode échatillon----- frame-based mode=mode base de donnée
block.RegBlockMethod('Outputs', @Outputs);
end
function Outputs(block)
%%% Paramètres de contrôle :
a0=0;
av=1;
c=80000;
b1=0;
b2=0;
u=zeros(1,10);
for i=1:10
if isfinite(block.InputPort(1).Data(i))
u(i)=block.InputPort(1).data(i); % création d'un vecteur de taille 6 contenant les entrées i
end
end
%%% Calcul des limites de la route et des potentiels de répulsion Urep %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yub=u(7); %upper boundary: limite sup de la route
ylb=u(8); %lower boundary: limite inf de la route
y_center_line= u(9); %center line: centre de la route
%% calcul des potentiels de répulsion Urep_1 et Urep_2, respectivement des limites sup et inf de la route
% Urep_1=zeros(1,1);
% Urep_2=zeros(1,1);
if (ylb<=u(5) && yub>=u(5))
Urep_1=b1/(u(5)-yub)^2;
Urep_2=b2/(u(5)-ylb)^2;
%% Fonction objective dont les variables d'entrées X(1) et X(2) sont
% respectivements la vitesse et l'angle de lacet désiré calculés par la fonction "fmincon",
% qui résout le problème d'optimisation avec contraintes posé:
% ici, le dernier terme de notre fonction objective ie c*(phi(k+1)-phi(k))^2
% qui représente le potentiel d'attraction, qui va attirer la cible jusqu'a sa destination final(goal!!)
% ici, phi(k) est la valeur initialle donnée par les équations du mouvement du véhicule
% notre ojectif est de trouver phi(k+1)!
vxd=u(6); % vitesse désirée ie vitesse longitudinale de la trajectoire
J=@(X)(a0*(u(6)-X(1))^2 + av*(X(1)*tan(X(2))-u(10))^2 + Urep_1 + Urep_2 + c*(X(2)-u(3))^2);
end
X0=[0,0]; %Initial point for X
A = [];
b = [];
Aeq=[]; %Matrix for linear equality constraints
beq=[]; %Vector for linear equality constraints
lb=[0,-pi/2]; %Vector of lower bounds
ub=[90,pi/2]; %Vector of upper bounds
opts = optimoptions(@fmincon,'Display','iter-detailed','Algorithm','sqp',...
'MaxFunEval',inf,'MaxIter',inf,'funvalcheck','on');
Q = fmincon(J,X0,A,b,Aeq,beq,lb,ub,[],opts); %% les valeurs réelles retournées sont la vitesse désirée et l'angle de lacet désiré
%% calcul des sorties :
block.OutputPort(1).Data(1) = vxd;
block.OutputPort(1).Data(2) = Q(2); % angle de lacet désiré
block.OutputPort(1).Data(3) = yub;
block.OutputPort(1).Data(4) = ylb;
block.OutputPort(1).Data(5) = y_center_line;
block.OutputPort(1).Data(6) = Q(1);
end
Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!