Professional Documents
Culture Documents
Scientific Computing: Optimization Toolbox Nonlinear Equations, Numerical Optimization
Scientific Computing: Optimization Toolbox Nonlinear Equations, Numerical Optimization
Lecture 4
Scientific Computing:
Optimization Toolbox
Nonlinear Equations, Numerical Optimization
Matthew J. Zahr
CME 292
Advanced MATLAB for Scientific Computing
Stanford University
Announcement
Lecture 4 of 8 (or 9)
Numerical Optimization (Optimization Toolbox)
Homework 1 due today
I’ll grade them on Friday
Homework 2 posted (only need to do 1 out of 4)
Need to start thinking about topics for Lecture 9
1 Definitions
3 Numerical Optimization
Optimization Solvers
Optimization Problems
Optimization Toolbox
Outline
1 Definitions
3 Numerical Optimization
Optimization Solvers
Optimization Problems
Optimization Toolbox
Gradient of f :
∂f h iT
∇f (x) = (x)T = ∂x
∂f
(x) · · · ∂f
∂xn (x)
∂x 1
Hessian of f :
∂f 2
∇2 f (x) ij =
(x)
∂xi ∂xj
Outline
1 Definitions
3 Numerical Optimization
Optimization Solvers
Optimization Problems
Optimization Toolbox
Problem Definition
Example
5
f (x) = x 2 + 1
4 f (x) = x 2
f (x) = x 2 − 1
3
f (x)
−1
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
x
Newton’s Method
f (xk )
xk+1 = xk −
f 0 (xk )
Demo: newton demo.m
fzero
Assignment
fsolve
Example
Derive Jacobian of
x1 − 4x21 − x1 x2
F(x) =
2x2 − x22 − 3x1 x2
Outline
1 Definitions
3 Numerical Optimization
Optimization Solvers
Optimization Problems
Optimization Toolbox
Problem Definition
minimize
n
f (x)
x∈R v
subject to Ax ≤ b
Aeq x = beq (2)
c(x) ≤ 0
ceq (x) = 0
`≤x≤u
Feasbile Set
Ax ≤ b
Aeq x = beq
c(x) ≤ 0 (3)
ceq (x) = 0
`≤x≤u
Lagrangian
where λ are the Lagrange mulitpliers for the inequality constraints and µ are
the Lagrange multipliers for the equality constraints.
Notice there is a Lagrange multiplier for each constraint, whether the
constraint is a simple bound, general linear, nonlinear, equality, or
inequality.
Optimality Conditions
∇x L(x∗ , λ∗ , µ∗ ) = 0
g(x∗ ) ≥ 0
h(x∗ ) = 0 (6)
∗
µ ≥0
∗T ∗ ∗T
λ g(x ) + µ h(x∗ ) = 0
Second-order necessary condition: ∇2xx L(x∗ , λ∗ , µ∗ ) 0
Second-order sufficient condition: ∇2xx L(x∗ , λ∗ , µ∗ ) 0
Derivative-free
Only function evaluations used
Brute force
Genetic algorithms
Finite difference computations of gradients/Hessians
Usually require very large number of function evaluations
Gradient-based
Most popular class of techniques
Function and gradient evaluations used
Finite difference computations of Hessians
SPD updates to build Hessian approximations (BFGS)
Hessian-based
Hessians usually difficult/expensive to compute, although often very
sparse
Second-order optimality conditions
Function, gradient, and Hessian evaluations used
Linear Program
minimize
n
fT x
x∈R v
subject to Ax ≤ b (7)
Aeq x = beq
`≤x≤u
minimize
n
fT x
x∈R v
subject to Ax ≤ b (8)
Aeq x = beq
xj ∈ {0, 1} for j ∈ {0, . . . , nv }
Quadratic Program
Unconstrained Optimization
minimize
n
f (x) (10)
x∈R v
MATLAB solvers
MATLAB solvers (fminunc, fminsearch)
fminsearch
Derivative-free
Simplex search
fminunc
Quasi-Newton with linesearch (medium scale)
Trust region reflexive (large scale)
General
minimize
n
f (x)
x∈R v
subject to Ax ≤ b (11)
Aeq x = beq
`≤x≤u
Bounds only
minimize
n
f (x)
x∈R v
(12)
subject to ` ≤ x ≤ u
MATLAB solvers (fminbnd, fmincon)
fminbnd
Single variable optimization
fmincon
Trust region reflexive method
Active-set method
minimize
n
f (x)
x∈R v
subject to Ax ≤ b
Aeq x = beq (13)
c(x) ≤ 0
ceq (x) = 0
`≤x≤u
Solvers
Trust region reflexive
Sequential Quadratic Programming (SQP)
Interior Point (IP)
Problem Structure
Options Structure
Each optimization solver has tunable options that can be specified with
an options structure
optimset <solver> to return options available for particular solver,
along with default values
Gives fine-grained control over optimization solver
Objective/Constriant functions
Maximum iterations
Tolerances
Difference intervals
Gradient, Hessian computations
Preconditioning
Scaling
Parallelization
Output and plotting functions
Optimization Functions
Linear Programming
linprog
Binary Integer Programming
bintprog
Quadratic Programming
quadprog
Unconstrained Optimization
fminsearch, fminunc
Constrained Optimization
General Nonlinear
fminbnd, fmincon, ktrlink
TOMLAB (commercial software)
Least Squares
Linear: lsqlin, lsqnonneg
Nonlinear: lsqcurvefit, lsqnonlin
Multiobjective Optimization
fgoalattain, fminimax
Objective Function
Assignment
Assignment
20 15
2 2
10
10 1.5 1.5
5
1 1
0 0.5 0 0.5
0 −5 0
−10
−0.5 −0.5
−10
−1 −1
−20 −15
−1.5 −1.5
2 1.5 x1 2 1.5 x1
1 0.5 1 0.5
0 −0.5 −2 0 −0.5 −2
−1 −1.5 −1 −1.5
−2 −2
x2 x2
Assignment
20
15
10
−5
−10
2
−15
0
−20
2 1.5 1 −2
0.5 0 −0.5 −1 −1.5 −2 x1
x2
Choosing an Algorithm
http://www.mathworks.com/help/optim/ug/choosing-a-solver.html