% ### LadderOPT.m ### 5.21.09 % simple code to numerically verify solution to Neuhaser's ladder % optimization problem clear % ---------- d= 20; % length of space between fence and house h= 13; % height of fence % --------- theta= linspace(0,pi/2,1000); % create range of possible angles % length of ladder as a function of theta (this is the function to minimize) L= d./cos(theta) + h./sin(theta); Lprime= d*(sin(theta))./(cos(theta).^2) - h*(cos(theta))./(sin(theta).^2); % derivative of above function % analytically derived solution for optimal angle; should match where F = 0 (which it does) thetaOPT= atan( (h/d)^(1/3) ); Lopt = h/sin(thetaOPT) + d/cos(thetaOPT); % corresponding minimum ladder length % ==== figure(1); clf; h1= plot(theta,L); grid on; hold on; h2= plot(theta,Lprime,'r-'); axis([-0.1 pi/2+0.1 -5 100]); ylabel('Length or deriv. [arb]'); xlabel('angle re fence [deg]'); title('Numerical check re ladder optimization problem'); %h3= plot(thetaOPT,Lopt,'kx','MarkerSize',8,'LineWidth',2); h3= stem(thetaOPT,Lopt,'k--'); legend([h1 h2 h3],'ladder length','deriv. of length','shortest length','Location','SouthWest')