Professional Documents
Culture Documents
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Optimization in Matlab
Kevin Carlberg
Stanford University
1 Overview
2 Optimization Toolbox
4 Function handles
5 GUI
6 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
Genetic Algorithm and Direct Search Toolbox: general
optimization problems
Direct search algorithms (directional): generalized pattern
search and mesh adaptive search
Genetic algorithm
Simulated annealing and Threshold acceptance
Kevin Carlberg Optimization in Matlab
Outline
Overview
Optimization Toolbox
Genetic Algorithm and Direct Search Toolbox
Function handles
GUI
Homework
Algorithms
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
Example: Creating a handle to an anonymous function
bowl = @(x,y)x^2+(y-2)^2;
ezsurf(bowl)
x2+(y!2)2
100
80
60
40
20
0
5
6
4
0 2
0
!2
!5 !4
y !6
x
100
80
60
40
20
0
5
6
4
0 2
0
!2
!5 !4
y !6
x
Supplying gradients
GUI
The optimization toolbox includes a graphical user interface
(GUI) that is easy to use
To activate, simply type optimtool at the command line
GUI options
Problem 1
Consider a convex function with constant Hessian
f (x1 , x2 ) = 4x12 + 7(x2 − 4)2 − 4x1 + 3x2
prob1 prob1
6
800
2
600
400
0
y
200
0 !2
6
4 !6
2 !4 !4
0 !2
!2 0
2
!4 4
!6 6 !6
y
x !6 !4 !2 0 2 4 6
x
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
500 0.2
y
400
! 0.2
300
1
! 0.4
200
0.5
! 0.6
100
0
! 0.8
0 ! 0.5
1
0.5 !1
0 !1 x !1 ! 0.8 ! 0.6 ! 0.4 ! 0.2 0 0.2 0.4 0.6 0.8 1
! 0.5
!1 x
y
Problem 3
Consider the Rastragin’s function, an all-around nasty
function. The global minimum is located at (x1 , x2 ) = (0, 0)
f (x1 , x2 ) = 20 + x12 + x22 − 10(cos 2πx1 + cos 2πx2 )
ras
ras
6
4
100
80 2
60
0
y
40
20 !2
0
5 !4
6
4
0 2
0
!2 !6
!5 !4
!6 !6 !4 !2 0 2 4 6
y x x