How to solve optimization problem with squared error sum in Simulink
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I have a Simulink model with 4 PIDs and a non-linear plant. I wrote a script running a sdo.SimulationTest and logging the output data and the input data of the model. Then I calculated the squared error sum J. Is it possible to use an optimizer minimizing this squared error sum and using the Parameters of the PID as variables. There is no functional connection between these two. Below is my code. Thank you
startSimulator;
sim_obj=sdo.SimulationTest('Hummingbird_Simulation_PositionControl_original')
Param=param.Continuous([2;1.5;2;2;1.5;2;5;1;2.8]);
Param.Minimum=[0;0;0;0;0;0;0;0;0];
Param.Maximum=[10;10;10;10;10;10;10;10;10];
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=length(W);
time=W_x.time;
E=[(W(1:length,1)-Y(1:length,1)).^2 (W(1:length,2)-Y(1:length,2)).^2 (W(1:length,3)-Y(1:length,3)).^2];
J=sum(sum(E));
end
2 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Design Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!