Unformatted text preview: 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 = x x  d . We can express y in terms 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 fminsearch. The function fminsearch finds the minimum of a function without using derivatives, using the Nelder Meads method that is based on evaluating the function on a simplex (the generalization of a triangle in higher dimension. The vertex with the highest value (worst) is eliminated and replaced by reflecting it about the centroid of the other points. See http://en.wikipedia.org/wiki/Nelder Mead_method and http://mathews.ecs.fullerton.edu/n2003/NelderMeadProof.html. In order to use fminsearch, we need to convert the ladder problem to an unconstrained problem. One standard way of doing it is by using a penalty for constraint violation. This is called a penalty 4x f = x + y + p y  x4 function method. So we replace our objective function with 2 2 2 For high values of p, we expect the solution to nearly satisfy the constraint. Let us visualize this function for different values of p. For p=10 we set >> ycon=4*xmat./(xmat4); >> fmat=lmat+10*(yconymat).^2; >> v={10 15 20 40 80]; >> cs=contour(xmat,ymat,fmat,v); clabel(cs) and we get 10 9.5 9 8.5 8 7.5 7 6.5 6 5.5 5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 80 15 20 20 15 40 80 40 For p=100 >> fmat=lmat+100*(yconymat).^2; >> cs=contour(xmat,ymat,fmat,v); clabel(cs) 10 9.5 9 15 8.5 8 7.5 7 6.5 6 5.5 5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 40 80 15 20 80 40 20 To nail down the position of the minimum with fminsearch, we need to specify a starting point with a vector rather than x,y, so we relabel them x1,x2. We define an anonymous function with the penalized length lpen=@(x) sqrt(x(1)^2+x(2)^2)+10*(x(2)4*x(1)/(x(1)4))^2 lpen = @(x) sqrt(x(1)^2+x(2)^2)+10*(x(2)4*x(1)/(x(1)4))^2 Pick a starting location and call fminsearch >> x0=[7 6]; >> fminsearch(lpen,x0) ans = 7.9941 7.9706 Now we increase the penalty and start where we left >> x0=xf; >> lpen=@(x) sqrt(x(1)^2+x(2)^2)+100*(x(2)4*x(1)/(x(1)4))^2 lpen = @(x) sqrt(x(1)^2+x(2)^2)+100*(x(2)4*x(1)/(x(1)4))^2 >> xf=fminsearch(lpen,x0) xf = 7.9994 7.9971 So that we are converging to the solution (8,8). To use fmincon we need to define an equality and inequality constraint vector. Since we have only an equality constraint we use function [c,ceq] =laddercon(x) ceq=x(2)4*x(1)/(x(1)4); c=; Then we invoke fmincon (use help fmincon to see the meaning of the other parameters). >> x0=[7 6]; >> sol=fmincon(@(x) x(1)^2+x(2)^2, x0,,,,,,,@(x) laddercon(x)) Warning: Largescale (trust region) method does not currently solve this type of problem, switching to mediumscale (line search). > In fmincon at 260 Optimization terminated: firstorder optimality measure less than options.TolFun and maximum constraint violation is less than options.TolCon. sol = 8.0000 8.0000 ...
View
Full
Document
This note was uploaded on 03/27/2012 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.
 Spring '09
 RAPHAELHAFTKA

Click to edit the document details