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

12 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 18 Apr 2018
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.
FloRida
FloRida on 18 Apr 2018
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.

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 18 Apr 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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!