part 2 chapter 7 - cauisdl.cau.ac.kr/education.data/numerical.analysis/lecture... · 2010-10-05 ·...
TRANSCRIPT
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
OptimizationOptimization
Prof. Prof. HaeHae--Jin ChoiJin Choi
[email protected]@cau.ac.kr
Part 2Part 2Chapter 7Chapter 7
1
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Chapter ObjectivesChapter Objectivesl Understanding why and where optimization occurs in engineering
and scientific problem solving.l Recognizing the difference between one-dimensional and multi-
dimensional optimization.l Distinguishing between global and local optima. l Locating the optimum of a single-variable function with the
golden-section search.l Locating the optimum of a single-variable function with parabolic
interpolation.l Knowing how to apply the fminbnd function to determine the
minimum of a one-dimensional function.l Knowing how to apply the fminsearch function to determine the
minimum of a multidimensional function
2
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
OptimizationOptimizationl Optimization is the process of creating something that is as
effective as possible.- Produce the greatest output for a given amount of input
l From a mathematical perspective, optimization deals with finding the maxima and minima of a function that depends on one or more variables.
( )( / )0 0( ) 1 c m tm mg mgz t z v e tc c c
-æ ö= + + - -ç ÷è ø
Elevation as a function of time for an object initially projected upward with an initial velocity
3
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Multidimensional OptimizationMultidimensional Optimizationl One-dimensional problems involve functions that depend on a
single dependent variable -for example, f(x).l Multidimensional problems involve functions that depend on two
or more dependent variables - for example, f(x,y)
4
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Global vs. LocalGlobal vs. Locall A global optimum represents the very best solution for the whole
range while a local optimum is better than its immediateneighbors. Cases that include local optima are called multimodal.
l Generally desire to find the global optimum.
5
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
GoldenGolden--Section SearchSection Searchl Search algorithm for finding a minimum on an interval [xl xu]
which includes a single minimum (unimodal interval)l Uses the golden ratio f=1.6180… to determine location of two
interior points x1 and x2; by using the golden ratio, one of the interior points can be re-used in the next iteration.
l This is similar to the bisection method (one middle point) except that two intermediate points are chosen according to the golden ratio.
1 2 1
1 2
21
2
let 1 0
1 5 1.618033988749892
f f f
f
+=
= ® - - =
+= =
l l ll lll
L
6
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
GoldenGolden--Section Search (cont)Section Search (cont)
1 2
1 2
1 2
( 1)( ) and
( ) 22( 1)( ) 2 ( ) 2( )
(2 3)( ) 0
u l
l u
l u l u
l u u l l u u l u l
u l
d x xx x d x x dx x x d x d x x dx x x x x x x x x x
x x x x
f
f ff
= - -
= + = -
- = + - - = - -
= - + - - = - + - - -
= - - > ® >
l If f(x1)<f(x2), x2 becomes the new lower limit and x1 becomes the new x2 (as in figure).
l If f(x1)>f(x2), x1 becomes the new upper limit and x2 becomes the new x1.
l In either case, only one new interior point is needed and the function is only evaluated one more time.
7
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Example7.2Example7.2l Q. Use the golden-section search to find the minimum of f(x)
within the interval from xl= 0 to xu=4.2
( ) 2sin10xf x x= -
For the first iteration
1
2
0.61803(4 0) 2.47210 2.4721 2.47214 2.4721 1.5279
dxx
= - == + == - =
2
2
2
1
1.5279( ) 2sin(1.5279) 1.764710
2.4721( ) 2sin(2.4721) 0.630010
f x
f x
= - = -
= - = -
i xl f(xl) x2 f(x2) x1 f(x1) xu f(xu) d 12345678
00
0.94430.94431.30501.30501.30501.3901
00
-1.5310-1.5310-1.7595-1.7595-1.7595-1.7742
1.52790.94431.52791.30501.52791.44271.39011.4427
-1.7647-1.5310-1.7647-1.7595-1.7647-1.7755-1.7742-1.7755
2.47211.52791.88851.52791.66561.52791.44271.4752
-0.6300-1.7647-1.5432-1.7647-1.7136-1.7647-1.7755-1.7732
4.00002.47212.47211.88851.88851.66561.52791.5279
3.1136-0.6300-0.6300-1.5432-1.5432-1.7136-1.7647-1.7647
2.47211.52790.94430.58360.36070.22290.13780.0851
8
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Absolute Errors in GoldenAbsolute Errors in Golden--Section SearchSection Search
l For each iteration, the optimum will fall in upper interval (x2,x1,xu) or lower interval (xl,x2,x1).
l Since the interior points (x1, x2) are symmetrical, either case can be used to define the error.
l Looking at the upper interval (x2,x1,xu) - If the true value were at the far left, the maximum distance
1 2
( 1)( ) ( 1)( )( ) 2( 1)( )(2 3)( ) 0.2361( )
a
l u l u u l
u l u l
u l u l
x x xx x x x x xx x x x
x x x x
f ff
f
D = -
= + - - - + - -
= - + - -
= - - = -
9
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
l Looking at the upper interval (x2,x1,xu) - If the true value were at the far right, the maximum distance
Absolute Errors in GoldenAbsolute Errors in Golden--Section Search(cont)Section Search(cont)
1
( 1)( )( ) ( 1)( )(2 )( ) 0.3820( )
b u
u l u l
u l u l
u l u l
x x xx x x xx x x x
x x x x
ff
f
D = -
= - - - -
= - - - -
= - - = -
l Normalization
(2 ) 100%u la
opt
x xx
e f-
= - ´ Error Criterion
10
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Code for GoldenCode for Golden--Section Search [1]Section Search [1]
function [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,varargin)% goldmin: minimization golden section search % [xopt,fopt,ea,iter]=goldmin(f,xl,xu,es,maxit,p1,p2,...):% uses golden section search to find the minimum of f% input:% f = name of function % xl, xu = lower and upper guesses% es = desired relative error (default = 0.0001%)% maxit = maximum allowable iterations (default = 50)% p1,p2,... = additional parameters used by f% output:% x = location of minimum
function [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,varargin)% goldmin: minimization golden section search % [xopt,fopt,ea,iter]=goldmin(f,xl,xu,es,maxit,p1,p2,...):% uses golden section search to find the minimum of f% input:% f = name of function % xl, xu = lower and upper guesses% es = desired relative error (default = 0.0001%)% maxit = maximum allowable iterations (default = 50)% p1,p2,... = additional parameters used by f% output:% x = location of minimum
11
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
% fx = minimum function value% ea = approximate relative error (%)% iter = number of iterationsif nargin<3,error('at least 3 input arguments required'),endif nargin<4|isempty(es), es=0.0001;endif nargin<5|isempty(maxit), maxit=50;endphi=(1+sqrt(5))/2;iter=0;while(1)d = (phi-1)*(xu - xl);x1 = xl + d;x2 = xu - d;
Code for GoldenCode for Golden--Section Search [2]Section Search [2]
12
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
if f(x1,varargin{:}) < f(x2,varargin{:})xopt = x1;xl = x2;
elsexopt = x2;xu = x1;
enditer=iter+1;if xopt~=0, ea = (2 - phi) * abs((xu - xl) / xopt) * 100;endif ea <= es | iter >= maxit,break,end
endx=xopt;fx=f(xopt,varargin{:});
Code for GoldenCode for Golden--Section Search [3]Section Search [3]
13
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Solve Example 7.1 by Golden Section SearchSolve Example 7.1 by Golden Section Search
Note : To transform the finding maximum value to finding minimum value, minus (-) sign is added to the equation.
>> g=9.81; v0=55; m=80;c=15;z0=100;>> z=@(t) –(z0+m/c*(v0+m*g/c)*(1-exp(-c/m*t))-m*g/c*t);>> [xmin,fmin,ea,iter]=goldmin(z,0,8)xmin =
3.8317fmin =-192.8609
ea = 6.9356e-005
14
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Parabolic InterpolationParabolic Interpolationl Another algorithm uses parabolic interpolation of three points to
estimate optimum location.
l The location of the maximum/minimum of a parabola defined as the interpolation of three points (x1, x2, and x3) is:
l The new point x4 and the two surrounding it (either x1 and x2or x2 and x3) are used for the next iteration of the algorithm.
�
x4 = x2 -12x2 - x1( )2 f x2( )- f x3( )[ ]- x2 - x3( )2 f x2( )- f x1( )[ ]x2 - x1( ) f x2( )- f x3( )[ ]- x2 - x3( ) f x2( )- f x1( )[ ]
15
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
fminbndfminbnd FunctionFunction
l MATLAB has a built-in function, fminbnd, which combines the golden-section search and the parabolic interpolation.>> [xmin, fval] = fminbnd(function, x1, x2)
l Options may be passed through a fourth argument using optimset, similar to fzero.
>> g=9.81; v0=55; m=80;c=15;z0=100;>> z=@(t) –(z0+m/c*(v0+m*g/c)*(1-exp(-c/m*t))-m*g/c*t);>> [x,f]=fminbnd(z,0,8)x =
3.8317f =-192.8609
16
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
>> options = optimset ('display', 'iter') ;>> fminbnd(z, 0, 8, options)
Func-count x f(x) Procedure1 3.05573 -189.759 initial2 4.94427 -187.19 golden3 1.88854 -171.871 golden4 3.87544 -192.851 parabolic5 3.85836 -192.857 parabolic6 3.83332 -192.861 parabolic7 3.83162 -192.861 parabolic8 3.83166 -192.861 parabolic9 3.83169 -192.861 parabolic
Optimization terminated:the current x satisfies the termination criteria usingOPTIONS.TolX of 1.000000e-004
ans =3.8317
17
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
Multidimensional VisualizationMultidimensional Visualizationl Functions of two-dimensions may be visualized using contour or
surface/mesh plots.
18
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
x=linspace(-2,0,40);y=linspace(0,3,40);[X,Y] = meshgrid(x,y);Z=2+X-Y+2*X.^2+2*X.*Y+Y.^2;subplot (1,2,1);cs=contour(X,Y,Z); clabel(cs);xlabel('x_1'); ylabel('x_2');title('(a) Contour plot') ;grid;subplot(1,2,2);cs=surfc(X,Y,Z);zmin=floor(min(Z));zmax=ceil(max(Z));xlabel('x_1'); ylabel ('x_2'); zlabel('f(x_1,x_2)');title ('(b) Mesh plot‘) ;
19
School of Mechanical EngineeringChung-Ang UniversityNumerical Methods 2010-2
fminsearchfminsearch FunctionFunctionl MATLAB has a built-in function, fminsearch, that can be used to
determine the minimum of a multidimensional function.
l The function must be written in terms of a single variable, where different dimensions are represented by different indices of that variable.
>> f=@(x) 2+x(1)-x(2)+2*x(1)^2+2*x(1)*x(2)+x(2)^2;>> [x, fval]=fminsearch(f, [-0.5, 0.5])x =
-1.0000 1.5000fval =
0.7500
20