Professional Documents
Culture Documents
Optimization in Matlab
Optimization in Matlab
Optimization in Matlab
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Optimization in Matlab
Kevin Carlberg
Stanford University
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
1 Overview
2 Optimization Toolbox
3 Genetic Algorithm and Direct Search Toolbox
4 Function handles
5 GUI
6 Homework
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Overview
Matlab has two toolboxes that contain optimization algorithms
discussed in this class
Optimization Toolbox
Unconstrained nonlinear
Constrained nonlinear
Simple convex: LP, QP
Least Squares
Binary Integer Programming
Multiobjective
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Nonlinear
Unconstrained: fminunc, fminsearch
Constrained: fmincon, fminbnd, fseminf
Discrete
Linear, Binary Integer Programming: bintprog
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Algorithms
Algorithms in this toolbox can be used to solve general
problems
All algorithms are derivative-free methods
Direct search: patternsearch
Genetic algorithm: ga
Simulated annealing/threshold acceptance: simulannealbnd,
threshacceptbnd
Genetic Algorithm for multiobjective optimization:
gamultiobj
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Function handles
Function handle: a MATLAB value that provides a means of
calling a function indirectly
Function handles can be passed in calls to other functions
Function handles can be stored in data structures for later use
The optimization and genetic algorithm toolboxes make
extensive use of function handles
100
80
60
40
20
0
5
0
!5
y
Kevin Carlberg
!6
!4
!2
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
100
80
60
40
20
0
5
0
!5
y
Kevin Carlberg
!6
!4
!2
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Supplying gradients
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
GUI
The optimization toolbox includes a graphical user interface
(GUI) that is easy to use
To activate, simply type optimtool at the command line
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
GUI options
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Create a handle for this function and use ezsurf to plot the
function
Create an optimization-ready handle for this function and
solve using different starting points using:
Kevin Carlberg
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Problem 1
Consider a convex function with constant Hessian
f (x1 , x2 ) = 4x12 + 7(x2 4)2 4x1 + 3x2
prob1
prob1
6
4
800
600
400
200
!2
0
6
4
!6
!4
0
!2
!4
!6
x
!2
!4
2
6
4
y
!6
!6
!4
!2
0
x
Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Problem 2
Consider the Rosenbrock function, a non-convex problem that
is difficult to minimize. The global minimum is located at
(x1 , x2 ) = (0, 0)
f (x1 , x2 ) = (1 x1 )2 + 100(x2 x12 )2
rosen
rosen
1
0.8
0.6
0.4
0.2
y
500
400
! 0.4
200
0.5
! 0.6
100
! 0.8
0
1
0
! 0.2
300
! 0.5
0.5
! 0.5
y
!1
!1
!1
!1
! 0.8
! 0.6
! 0.4
! 0.2
0
x
Optimization in Matlab
0.2
0.4
0.6
0.8
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Problem 3
Consider the Rastragins function, an all-around nasty
function. The global minimum is located at (x1 , x2 ) = (0, 0)
f (x1 , x2 ) = 20 + x12 + x22 10(cos 2x1 + cos 2x2 )
ras
ras
4
100
80
60
40
20
!2
0
5
!4
0
!5
y
!6
!4
!2
!6
!6
!4
!2
0
x
Optimization in Matlab