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

조회 수: 12 (최근 30일)
FloRida
FloRida 2018년 4월 17일
댓글: FloRida 2018년 4월 18일
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