Undefined function '[function name] ' for input arguments of type 'double'.
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
FloRida
el 17 de Abr. de 2018
Comentada: FloRida
el 18 de Abr. de 2018
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
Walter Roberson
el 18 de Abr. de 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.
Respuesta aceptada
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)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!