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 Tutorialfunction [Kp,Ki,Kd] = runtracklsq% RUNTRACKLSQ demonstrates using LSQNONLIN with Simulink.optsim% Load the modelpid0 = [0.63 0.0504 1.9688]; % Set initial valuesa1 = 3; a2 = 43;% Initialize model plant variablesoptions = optimset('LargeScale','off','Display','iter',...'TolX',0.001,'TolFun',0.001);pid = lsqnonlin(@tracklsq, pid0, [], [], options);Kp = pid(1); Ki = pid(2); Kd = pid(3);function F = tracklsq(pid)% Track the output of optsim to a signal of 1% Variables a1 and a2 are needed by the model optsim.% They are shared with RUNTRACKLSQ so do not need to be% redefined here.Kp = pid(1);Ki = pid(2);Kd = pid(3);% Compute function valuesimopt = simset('solver','ode5',...'SrcWorkspace','Current');% Initialize sim options[tout,xout,yout] = sim('optsim',[0 100],simopt);F = yout-1;endendWhen you run runtracklsq, the optimization gives the solution for theproportional, integral, and derivative (Kp, Ki, Kd) gains of the controller after64 function evaluations.[Kp, Ki, Kd] = runtracklsqDirectionalIteration Func-count Residual Step-size derivative Lambda0 4 8.665312-30

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

Saved successfully!

Ooh no, something went wrong!