Undefined function '[function name] ' for input arguments of type 'double'.

I got this error message although my [function name] is no function but rather a input variable to an objective function used in fmincon. This is my code:
function Param_Optim = Optimizer
startSimulator;
Param_Start=[2;1.4;2;2;1.4;2];
lb=[0;0;0;0;0;0];%lower boundary
ub=[10;10;10;10;10;10];%upper boundary
options = optimoptions('fmincon','MaxIter',5,'Display','iter-detailed');
[Param_Optim,fval]= fmincon(@fun,Param_Start,[],[],[],[],lb,ub,[],options);
Param_Optim
fval
end
function J = fun(Param_Value)
sim_obj=sdo.SimulationTest('Hummingbird_Simulation_PositionControl_original');
Param_Value;
%Param=param.Continuous(Param_Value);
%sim_obj.Parameters=Param;
sim_obj.LoggingInfo.LoggingMode='LogAllAsSpecifiedInModel';
sim_out=sim(sim_obj);
Y_x=sim_out.LoggedData.get('logsout').getElement('X').Values;
Y_y=sim_out.LoggedData.get('logsout').getElement('Y').Values;
Y_z=sim_out.LoggedData.get('logsout').getElement('Z').Values;
W_x=sim_out.LoggedData.get('logsout').getElement('X_cmd').Values;
W_y=sim_out.LoggedData.get('logsout').getElement('Y_cmd').Values;
W_z=sim_out.LoggedData.get('logsout').getElement('Z_cmd').Values;
W=[W_x.get('Data') W_y.get('Data') W_z.get('Data')];
Y=[Y_x.get('Data') Y_y.get('Data') Y_z.get('Data')];
length_W=length(W);
%time=W_x.time;
E=[(W(1:length_W,1)-Y(1:length_W,1)).^2 (W(1:length_W,2)-Y(1:length_W,2)).^2 (W(1:length_W,3)-Y(1:length_W,3)).^2 ];
J=sum(sum(E));
% hold on
% plot(time,W(1:length_W,1),time,Y(1:length_W,1));
% figure
% plot(time,W(1:length_W,2),time,Y(1:length_W,2));
% figure
% plot(time,W(1:length_W,3),time,Y(1:length_W,3));
end

6 comentarios

Which line is the problem occurring on? Which name is it giving?
On the following line: Param_Value;
Matlab takes Param_Value as function, although it is in the definition of the function contained as input.
sdo.SimulationTest or Hummingbird_Simulation_PositionControl_original might contain a "clear all" somewhere in it.
FloRida
FloRida el 18 de Abr. de 2018
Editada: FloRida el 18 de Abr. de 2018
First of all, thank you for your help. My problem is, that i do not really get how fmincon works. I understood Param_Value as some kind of a control variable so it is not defined before. I thought that fmincon would call the function fun with its initial guess first and therefore Param_Value would take on the value Param_Start in the first simulation. Afterwards it would be changed by fmincon to minimize the value J. But neither of this happens.
That understanding is correct. However you are calling a simulation routine within your objective function, and if that simulation routine contains a "clear all" then you metaphorically shoot the leg you are standing on and Param_Value would be erased along with all of the other "all" that "clear all" clears.
Okay. But how can a simulation contain a clear all? Where may I find it? However, when I run the optimizer file now, there is no error, but the result is the start vector with 0 iterations of fmincon and a f-count of 7. And if i change the starting vector it does the same, so the starting vector's not the optimum.

Iniciar sesión para comentar.

 Respuesta aceptada

Alan Weiss
Alan Weiss el 18 de Abr. de 2018

Sometimes you need to change the finite difference step size, as explained in Optimizing a Simulation or ODE.

Alan Weiss

MATLAB mathematical toolbox documentation

Más respuestas (0)

Preguntada:

el 17 de Abr. de 2018

Comentada:

el 18 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by