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

12 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2018-4-18
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 2018-4-18
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.

请先登录,再进行评论。

采纳的回答

Alan Weiss
Alan Weiss 2018-4-18

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

Alan Weiss

MATLAB mathematical toolbox documentation

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by