Optimization

Optimization
using Matlab
references:
• EN40 Matlab tutorial §14
• online Matlab documentation
Section 02/22/17, Odysseus Skartsis
Example 1: Unconstrained optimization
Find minimum value of the objective function:
z(x,y) = sin(x) sin(y)
Contour plot of function z(x,y)
Contour plot of function z(x,y)
6
4
1
0.8
0.6
2
0.4
0.2
y
0
-0.2
0
-0.4
-0.6
-2
-0.8
-1
8
6
4
10
2
5
0
-2
y
-4
0
-4
-5
-6
-8
-10
x
-6
-6
-4
-2
0
x
2
4
6
Example 1: Unconstrained optimization
command syntax:
[x,fval]=fminunc(@funName,iniGuess,options)
code snippet:
functionminimize_demo
% give initial conditions
iniGuess=[x0,y0,etc.]
% call optimizer
[desVarsOpt,fOpt]=fminunc(@funName,iniGuess)
end
% define the function
functionzVal=funName(desVars)
end
Example 2: Constrained optimization
Find minimum value of the objective function:
z(x,y) = sin(x) sin(y)
under the constraints:
3.5 ≤ x ≤ 4 & 0 ≤ y ≤ 4
Contour plot of function z(x,y)
Contour plot of function z(x,y)
6
4
1
0.8
0.6
2
0.4
0.2
y
0
-0.2
0
-0.4
-0.6
-2
-0.8
-1
8
6
4
10
2
5
0
-2
y
-4
0
-4
-5
-6
-8
-10
x
-6
-6
-4
-2
0
x
2
4
6
Example 2: Constrained optimization
command syntax (some flavors):
[x,fval]=fmincon(@funName,iniGuess,A,b)
y
example constraints:
• m1 < 3 kg
• k1 > 5 N/m
x
[x,fval]=fmincon(@funName,iniGuess,A,b,Aeq,beq)
y
example constraints:
• m1 < 3 kg
• k1 > 5 N/m
• k1 = (3 Hz2) * m1
x
[x,fval]=fmincon(@funName,iniGuess,A,b,Aeq,beq,lb,ub)
y
example constraints:
• m1 < 3 kg
• k1 > 5 N/m
• k1 = (3 Hz2) * m1
• m1 ∈ [0.2, 1000] g
x
[x,fval]=fmincon(@funName,iniGuess,A,b,Aeq,beq,lb,ub,nonlcon)
example constraints:
y
• (x-xc)2 + (y-yc)2 < ρ2
x
Example 2: Constrained optimization
so, how do you get from this syntax…
[x,fval]=fmincon(@funName,iniGuess,A,b,Aeq,beq,lb,ub)
y
example constraints:
3.5 ≤ x ≤ 4 & 0 ≤ y ≤ 4
x
…this less stringent constraint?
[x,fval]=fmincon(@funName,iniGuess,A,b,Aeq,beq,lb,ub)
example constraints:
y
• m1 ∈ [0.2, 1000] g
• k1 ∈ [2, 5] N/m
x
Example 2: Constrained optimization
Find minimum value of the objective function:
z(x,y) = sin(x) sin(y)
under the constraints:
x ≥ 2 & y ≥ -1
and:
4x + 3y ≤ 6
Contour plot of function z(x,y)
Contour plot of function z(x,y)
6
4
1
0.8
0.6
2
0.4
0.2
y
0
-0.2
0
-0.4
-0.6
-2
-0.8
-1
8
6
4
10
2
5
0
-2
y
-4
0
-4
-5
-6
-8
-10
x
-6
-6
-4
-2
0
x
2
4
6
Example 2: Constrained optimization
so, how do you get from this syntax…
[x,fval]=fmincon(@funName,iniGuess,A,b,Aeq,beq,lb,ub)
y
example constraints:
• 3.5 ≤ x ≤ 4 & 0 ≤ y ≤ 4
x
…this less stringent constraint?
[x,fval]=fmincon(@funName,iniGuess,A,b,Aeq,beq,lb,ub)
y
example constraints:
• x ≥ 2 & y ≥ -1
• 4x + 3y ≤ 6
x
Optimization is “the action of making the best use of a resource.”
• 300 BC, Euclid The Elements
- Among all [possible] rectangles
with given total length of edges,
which has the greatest area?
- The square.
1. design variables
3. constraint
2. function to be optimized
(i.e., min or max)
historical perspective
• 300 BC, Euclid The Elements, Isoperimetric rectangle with greatest area
• 200 BC, Zenodorus Dido’s problem, Greatest area under a curve
• 100 BC, Heron Catoptrica, Light travels shortest path off mirror
• 1615, Kepler The Elements, Isoperimetric rectangle with greatest area
• 1638, Galilei Catenary shape problem, …
• 1636, Fermat f’(xmin,max) = 0, light travels shortest optical path between two points
• 1660-70, Newton & Leibniz Mathematical basis for calculus of variations
• 1696, Bernoulli bros Brachistochrone problem
• 1740, Euler General theory of calculus of variations
• 1746, de Maupertuis Principle of least action for physical phenomena
• 1788, Lagrange Méchanique Analitique, Lagrange multipliers (Méthode des multipliers) …
• 1806, Legendre & Gauss Least squares method
• 1847, Cauchy Gradient method
• 1847, Gibbs Chemical equilibrium is an energy minimum
…
• 1951, Kuhn & Tucker Optimal conditions for nonlinear problems
…
• 2017, ENGN40 class Mass launcher project, Maximum launch velocity of projectile
escape slides: min time of decent
travel time: shortest path of curved surfaces
networks: shortest length
Optimal = min (or max)
from Matlab’s Optimization toolbox:
EN40 Tutorial
example 1
example 2
EN40 Tutorial
EN40 Tutorial
EN40 Tutorial
- how to choose?
- see Optimization Decision Table:
https://www.mathworks.com/help/optim/ug/optimization-decision-table.html