Numerical Operations S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Optimization Toolbox
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 2 Optimization Topics n Unconstrained Optimization Unconstrained Optimization n Constrained Optimization Constrained Optimization n Constrained Box Example Constrained Box Example
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 3 2) Invoke the Optimization Routine n Use the following Steps: 1) Create an M-file of the function Unconstrained Optimization n Find a set of values of [x1, x2] that minimizes the function f(x 1,x 2 ):
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 4 Create fun.m M-File n The created M-file fun.m will contain: n Create an M-File function to evaluate the following function of two variables function f=fun(x) %x=[x1 x2] f=exp(x(1))*(4*x(1)^2 + 2*x(2)*x(2) + 4*x(1)*x(2) + 2*x(2) + 1);
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 5 Invoke Optimization n Invoke Optimization with Initial Guess for Input variables: X 1 = -1 and X 2 = 1 » x0=[-1,1]; % Starting Guess n Minimum Solution: f(x1,x2) = x when X 1 = 0.5 and X 2 = -1 » x=fminu('fun',x0)% Find Minimum of Function x = » fun(x) ans = e-010
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 6 Constrained Example n Minimize: n With the Constraints: n The M-File fun.m will contain: function [f,g]=fun(x) %x=[x1 x2] f=exp(x(1))*(4*x(1)^2 + 2*x(2)*x(2) + 4*x(1)*x(2) + 2*x(2)+1); g(1)=1.5+x(1)*x(2)-x(1)-x(2); g(2)=-x(1)*x(2)-10;
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 7 Constrained Optimization » x0=[-1,1]; % Starting Guess » x=constr('fun',x0) Different Solution than Unconstrained Case x = » fun(x) ans =
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 8 Constrained Box Example n Design a box using cardboard, Volume<100 x2x2 x3x3 x1x1 Double Flaps u Area of Cardboard = 2x 1 x 3 +2x 2 x 3 +4x 2 x 1 (function) Volume = x 1 x 2 x 3 100 (constraint)
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 9 Create Box M-File n Create box.m M-file function function [f,g]=box(x) f=2*x(1)*x(3)+2*x(2)*x(3)+4*x(2)*x(1); g=100-x(1)*x(2)*x(3); Area of Cardboard = 2x 1 x 3 +2x 2 x 3 +4x 2 x 1 (function f) Volume = x 1 x 2 x 3 100 (constraint g)
Numerical Operations: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Optimization 10 Run Box Optimization n Run optimization in Matlab » x0=[ ];% First Guess n Minimum Area = when x 1 =x 2 = and x 3 = » x=constr('box',x0)% Minimize x = x 1 x 2 x 3 » box(x) % Calculate Area ans =