Unformatted text preview: The golden search method is good when you are far away from the solution, and when you have the solution bounded. In other cases, parabolic interpolation is preferable, provided that you do not allow it to take you too far away. Consider for example finding the maximum of sin(x). We need three points for fitting a parabola, and if we start far away we may use x=[0,0.1,0.2] >> x=[0,0.1,0.2] x = 0 0.1000 0.2000 >> y=sin(x) y = 0 0.0998 0.1987 We can now use the function polyfit (see Section 15.1.2) to fit a parabola to the data c=polyfit(x,y,2) c = 0.0499 1.0033 0.0000 Since for low values of x, sin(x)=xx3/6, the quadratic term is very small, and the parabola does not fit well. The approximation is yp=0.0499x2+1.0033x, or c(1)*x^2+c(2)*x+c(3). The derivative Y'p=2*c(1)*x+c(2) has a zero at 0.5*c(2)/c(1) maxapx=0.5*c(2)/c(1) maxapx = 10.0583 This is a very poor result. However, if we start closer >> x=[1,1.1,1.2]; >> y=sin(x); >> c=polyfit(x,y,2) c = 0.4452 1.4324 0.1456 >> maxapx=0.5*c(2)/c(1) maxapx= 1.6085 We can now shift the sequence as >> x=[1.1,1.2,maxapx]; >> y=sin(x); >> c=polyfit(x,y,2); >> maxapx=0.5*c(2)/c(1) maxapx = 1.5760 And we are now very close to the root 1.5708. We can find the root with Matlab function fminbnd. It uses a combination of golden search and parabolic interpolation. We first set the options so that we will get a display of the iterations: >> options=optimset('display','iter') options = Display: 'iter' MaxFunEvals: MaxIter: TolFun: TolX: There are many other functions, but the above five are the most commonly used. Next we need to define an anonymous function that Is the negative of the sine function, because fminbnd calculates minima rather than maxima. >> [email protected](x) sin(x) msin = @(x) sin(x) Then we invoke fminbnd >> fminbnd(msin,1,3,options) Funccount x f(x) Procedure 3 1.76393 0.981407 initial 4 2.23607 0.786749 golden 5 1.47214 0.995137 golden 6 1.56883 0.999998 parabolic 7 1.57087 1 parabolic 8 1.5708 1 parabolic 9 1.57076 1 parabolic 10 1.57083 1 parabolic If we asked for the minimum of the function in the same interval, Matlab would have more trouble because the minimum is on the boundary >> fminbnd(@sin,1,3,options) Funccount x f(x) Procedure 3 1.76393 0.981407 initial 4 2.23607 0.786749 golden 5 2.52786 0.57592 golden 6 2.7082 0.419949 golden 7 2.81966 0.3164 golden 8 2.88854 0.250357 golden 9 2.93112 0.208926 golden 10 2.95743 0.183126 golden 11 2.97369 0.167116 golden 12 2.98374 0.157199 golden 13 2.98995 0.151062 golden 14 2.99379 0.147266 golden 15 2.99616 0.144919 golden 16 2.99763 0.143468 golden 17 2.99853 0.142571 golden 18 2.99909 0.142017 golden 19 2.99944 0.141674 golden 20 2.99965 0.141463 golden 21 2.99979 0.141332 golden 22 2.99987 0.141251 golden 23 2.99992 0.141201 golden 24 2.99995 0.141168 golden Problem 33 in the textbook asks us to find the shortest ladder that will reach the wall given the obstacle in between. We denote the horizontal distance of the foot of the ladder as x, and the height at the wall as y, and then the length that we want to minimize is given as L = x 2 + y 2 . We also have a geometric constraint that y h . We can express y in terms = x xd
of x and solve as one dimensional minimization. Instead we will solve as a two dimensional problem with a constraint graphically. Consider, for example the case where h=d=4. Then we would like to generate first a matrix of x and y values. Intuitively it would appear that we can limit ourselves to the range (5,10). So >> x=linspace(5,10,101); >> y=linspace(5,10,101); We then inflate these to a matrix of x and y values (101x101) >> one101=ones(1,101); >> xmat=x'*one101; >> ymat=one101'*y; >> lmat=sqrt(xmat.^2+ymat.^2); These matrix operations are not easy to understand, so perform them without the semicolumn with a small number of points in order to see it working. We also generate the constraint function >> ycon=4*x./(x4); Then plot with labels, and superimpose the constraint >> cs=contour(xmat,ymat,lmat); clabel(cs) >> hold on >> plot(x,ycon,'o') 10 9.5 9 8.5 8 7.5 7 6.5 6 5.5 5 5 5.5 8 8 6 6.5 7 7.5 8 8.5 9 9.5 10 11 12 11 12 13 14 13 9 9 10 10 >> From the figure we can see that the shortest ladder will be about 11.3. We can get a more accurate answer by repeating In a smaller region (say between 7.5 and 8.5) or using fminsrch. ...
View
Full Document
 Spring '09
 RAPHAELHAFTKA
 Optimization, shortest ladder, parabolic interpolation, golden search method

Click to edit the document details