Download presentation
Presentation is loading. Please wait.
Published byLesley Stokes Modified over 9 years ago
2
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
3
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
4
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 ):
5
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);
6
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) = 1.3029x10 -10 when X 1 = 0.5 and X 2 = -1 » x=fminu('fun',x0)% Find Minimum of Function x = 0.5000 -1.0000 » fun(x) ans = 1.3029e-010
7
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;
8
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 = -9.5474 1.0474 » fun(x) ans = 0.0236
9
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)
10
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)
11
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=[4.64 4.64 4.64];% First Guess n Minimum Area = 162.8651 when x 1 =x 2 =3.6840 and x 3 =7.3681 » x=constr('box',x0)% Minimize x = 3.6840 3.6840 7.3681 x 1 x 2 x 3 » box(x) % Calculate Area ans = 162.8651
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.