12.07.2015 Views

What Is Optimization Toolbox?

What Is Optimization Toolbox?

What Is Optimization Toolbox?

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2 Tutorialcalling the simulation twice by using nested functions so that the value ofyout can be shared between the objective and constraint functions as long asit is initialized in runtrackmm.Thefollowingisthecodeforruntrackmm:function [Kp, Ki, Kd] = runtrackmmoptsimpid0 = [0.63 0.0504 1.9688];% a1, a2, yout are shared with TRACKMMOBJ and TRACKMMCONa1 = 3; a2 = 43; % Initialize plant variables in modelyout = []; % Give yout an initial valueoptions = optimset('Display','iter',...'TolX',0.001,'TolFun',0.001);pid = fminimax(@trackmmobj,pid0,[],[],[],[],[],[],...@trackmmcon,options);Kp = pid(1); Ki = pid(2); Kd = pid(3);function F = trackmmobj(pid)% Track the output of optsim to a signal of 1.% Variables a1 and a2 are shared with RUNTRACKMM.% Variable yout is shared with RUNTRACKMM and% RUNTRACKMMCON.endKp = pid(1);Ki = pid(2);Kd = pid(3);% Compute function valueopt = simset('solver','ode5','SrcWorkspace','Current');[tout,xout,yout] = sim('optsim',[0 100],opt);F = yout;function [c,ceq] = trackmmcon(pid)% Track the output of optsim to a signal of 1.% Variable yout is shared with RUNTRACKMM and% TRACKMMOBJ2-34

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!