{"id":1349,"date":"2016-02-29T12:00:22","date_gmt":"2016-02-29T17:00:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=1349"},"modified":"2016-02-25T16:46:00","modified_gmt":"2016-02-25T21:46:00","slug":"the-classic-crossed-ladders-puzzle","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2016\/02\/29\/the-classic-crossed-ladders-puzzle\/","title":{"rendered":"The Classic Crossed Ladders Puzzle"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><!--introduction--><p>Here is a classic puzzle. A pair of ladders leaning against the sides of an alley form a lopsided cross.  Each ladder is propped against the base of one wall and leans against the opposite wall. If one ladder is 30 feet long, the other 20 feet long, and the point where they cross 10 feet above the ground, how wide is the alley?<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#85bbc259-74c9-4c77-af17-e2578c08b078\">Eight variables<\/a><\/li><li><a href=\"#c4b0515d-3d53-4a20-aa1e-09a9a95b9b4c\">The equations<\/a><\/li><li><a href=\"#a5c4e231-d04b-4947-a7c9-0f0155bcadf1\">Harmonic mean<\/a><\/li><li><a href=\"#af246fb5-8387-4fe2-9600-f5607f363f46\">Smallest integer solution<\/a><\/li><li><a href=\"#112b4fa3-abab-4471-8bbc-fbb4dfd4a346\">Puzzle<\/a><\/li><li><a href=\"#81083d10-4e46-4ad7-a54f-10f43428931f\">The gorilla in the room<\/a><\/li><li><a href=\"#0e472366-cc82-42dd-8b28-8406e760e994\">Ladders App<\/a><\/li><li><a href=\"#a27d8ef1-dba2-439a-b84b-f77d8476c54f\">Acknowledgement<\/a><\/li><\/ul><\/div><h4>Eight variables<a name=\"85bbc259-74c9-4c77-af17-e2578c08b078\"><\/a><\/h4><p>The lengths of the ladders are denoted by $a$ and $b$. The height of the crossing is $c$. The heights of the points where the ladders reach the walls are $x$ and $y$. The bases of the right triangles whose common height is the crossing are $u$ and $v$. Finally, the width of the alley is $w$. Here is the picture.<\/p><pre class=\"codeinput\">   ladders_diagram(<span class=\"string\">'vars'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/ladders_blog_01.png\" alt=\"\"> <h4>The equations<a name=\"c4b0515d-3d53-4a20-aa1e-09a9a95b9b4c\"><\/a><\/h4><p>These eight variables are connected by five equations. The Pythagorean Theorem provides two equations.<\/p><p>$$ a^2 = x^2 + w^2 $$<\/p><p>$$ b^2 = y^2 + w^2 $$<\/p><p>The ratios between sides of similar triangles provide two more.<\/p><p>$$ \\frac{x}{w} = \\frac{c}{v} $$<\/p><p>$$ \\frac{y}{w} = \\frac{c}{u} $$<\/p><p>The fifth equation is a simple linear relation that ties the two triangles together.<\/p><p>$$ w = u + v $$<\/p><p>Five equations involving eight variables leaves three degrees of freedom. In principle we could specify any three of the variables and solve for the other five.  But that may or may not be easy. We will have two different situations in what follows.  The puzzle posed in the opening paragraph specifies $a$, $b$ and $c$, and asks to find $w$.  This is nontrivial.  On the other hand, our graphic app is driven by $x$, $y$ and $w$.  When these three are pinned down by mouse clicks, the other five follow immediately.<\/p><h4>Harmonic mean<a name=\"a5c4e231-d04b-4947-a7c9-0f0155bcadf1\"><\/a><\/h4><p>Combining the last three equations generates an elegant relation. This isn't a new equation; it's a consequence of the ones we already have.<\/p><p>$$ \\frac{1}{c} = \\frac{1}{x} + \\frac{1}{y} $$<\/p><p>This says that the height of the crossing is one-half of the <i>harmonic mean<\/i> of the heights of the two ladders. The equation is a familiar one in <i>optics<\/i>, where it is known as the <i>thin lens equation<\/i>.  It relates the location of an image to the object distance and focal length.<\/p><h4>Smallest integer solution<a name=\"af246fb5-8387-4fe2-9600-f5607f363f46\"><\/a><\/h4><p>The following picture shows a solution of these equations where all eight variables have integer values.  In fact, if we collect all eight variables into a vector $s$.<\/p><p>$$ s = [a, b, c, u, v, w, x, y] $$<\/p><p>And use the 1-norm to measure the \"size\" of a solution.<\/p><p>$$ ||s||_1 = \\sum_{i=1}^8 s_i $$<\/p><p>Then ITOT (\"It Turns Out That\") this is smallest solution with all integer elements.<\/p><pre class=\"codeinput\">   ladders_diagram(<span class=\"string\">'vals'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/ladders_blog_02.png\" alt=\"\"> <h4>Puzzle<a name=\"112b4fa3-abab-4471-8bbc-fbb4dfd4a346\"><\/a><\/h4><p>Combining Pythagoras and optics provides a single nonlinear equation for $w$ in terms of $a$, $b$ and $c$.<\/p><p>$$ \\frac{1}{\\sqrt{a^2 - w^2}}+\\frac{1}{\\sqrt{b^2 - w^2}}=\\frac{1}{c} $$<\/p><p>It is not difficult to use the one-dimensional MATLAB zero finder <tt>fzero<\/tt> with fixed values for <tt>a<\/tt>, <tt>b<\/tt> and <tt>c<\/tt> to compute a solution of this equation.<\/p><pre class=\"codeinput\">   a = 30;\r\n   b = 20;\r\n   c = 10;\r\n   F = @(w) 1.\/sqrt(a^2 - w.^2) + 1.\/sqrt(b^2 - w.^2) - 1\/c\r\n   w = fzero(F,c)\r\n<\/pre><pre class=\"codeoutput\">F = \r\n    @(w)1.\/sqrt(a^2-w.^2)+1.\/sqrt(b^2-w.^2)-1\/c\r\nw =\r\n   12.3119\r\n<\/pre><p>So this is the answer to the puzzle.  For the prescribed values of the lengths of the ladders and the height of the crossing point, the width of the alley has to be about <tt>12.3<\/tt> feet.<\/p><p>A graph of <tt>F(w)<\/tt> in the vicinity of its zero shows why <tt>fzero<\/tt> has no trouble.<\/p><pre class=\"codeinput\">   ezplot(F,[10,15])\r\n   set(gca,<span class=\"string\">'xaxislocation'<\/span>,<span class=\"string\">'origin'<\/span>)\r\n   line(w,0,<span class=\"string\">'marker'<\/span>,<span class=\"string\">'.'<\/span>,<span class=\"string\">'markersize'<\/span>,24,<span class=\"string\">'color'<\/span>,<span class=\"string\">'k'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/ladders_blog_03.png\" alt=\"\"> <h4>The gorilla in the room<a name=\"81083d10-4e46-4ad7-a54f-10f43428931f\"><\/a><\/h4><p>It is easy to solve our single nonlinear equation numerically to compute $w$, but to find an analytic solution is a formidable challenge, even for computer algebra systems.  Historically, the approach has focused on an equivalent quartic polynomial.<\/p><p>Take $a = 40$, $b = 30$ and $c = 20$.  Let<\/p><p>$$ z = w^2 $$<\/p><p>Multiply through by the expressions in the denominators to put everything on one level.<\/p><p>$$ 10\\, \\sqrt{400 - z} + 10\\, \\sqrt{900 - z} = \\sqrt{400 - z}\\, \\sqrt{900 - z} $$<\/p><p>Now square both sides to get rid of the sqrt's on the right.  Then rearrange terms and square everything again to eliminate the remaining sqrt's. If you're careful, you will eventually reach a polynomial of degree 4 in $z$.<\/p><p>$$ z^4 - 2200\\, z^3 + 1630000\\, z^2 - 454000000\\, z + 38500000000 = 0 $$<\/p><p>But we're only halfway there.  We still have to solve this quartic. In principle it is possible to do this analytically, but let's again abandon algebraic and resort to numeric techniques.<\/p><pre class=\"codeinput\">   poly = [ 1, -2200, 1630000, -454000000, 38500000000];\r\n   z = roots(poly)\r\n<\/pre><pre class=\"codeoutput\">z =\r\n   1.0e+02 *\r\n   8.4877 + 0.5881i\r\n   8.4877 - 0.5881i\r\n   3.5087 + 0.0000i\r\n   1.5158 + 0.0000i\r\n<\/pre><p>The repeated squaring has produced extraneous roots.  ITOT that we can recover $w$ from the fourth one.<\/p><pre class=\"codeinput\">   w = sqrt(z(4))\r\n<\/pre><pre class=\"codeoutput\">w =\r\n   12.3119\r\n<\/pre><p>It is reassuring to find the same width.<\/p><h4>Ladders App<a name=\"0e472366-cc82-42dd-8b28-8406e760e994\"><\/a><\/h4><p>I am having a lot of fun with an interactive graphical experience where you vary any one of four parameters and see how it affects the others.  You can change the height of the points where the ladders hit the wall, or change the width of the alley.  You will find that dragging any one of these three control points affects only a couple of the other quantities.<\/p><p>You will see more action when you vary the crossing point.  This changes all of the values except the width.  Of course, it is not physically realistic to expect to alter the lengths of the ladders by changing where they cross, but that would actually have to happen if they were constrained to meet the walls.<\/p><p>The complete program for this app is the subject for my blog in two weeks.  The title is \"Investigating the Classic Crossed Ladders Puzzle\". <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2016\/03\/14\/investigating-the-classic-crossed-ladders-puzzle\">This link<\/a> should be good after March 14.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/ladders_movie.gif\" alt=\"\"> <\/p><h4>Acknowledgement<a name=\"a27d8ef1-dba2-439a-b84b-f77d8476c54f\"><\/a><\/h4><p>Thanks to Ned Gulley of MathWorks for suggesting that this classic puzzle warrants another look.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_9d7b0418c4904be7a546ded01ffedeb9() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='9d7b0418c4904be7a546ded01ffedeb9 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 9d7b0418c4904be7a546ded01ffedeb9';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2016 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_9d7b0418c4904be7a546ded01ffedeb9()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2016a<br><\/p><\/div><!--\r\n9d7b0418c4904be7a546ded01ffedeb9 ##### SOURCE BEGIN #####\r\n%% The Classic Crossed Ladders Puzzle\r\n% Here is a classic puzzle.\r\n% A pair of ladders leaning against the sides of an alley form a lopsided\r\n% cross.  Each ladder is propped against the base of one wall and leans\r\n% against the opposite wall.\r\n% If one ladder is 30 feet long, the other 20 feet long, and the\r\n% point where they cross 10 feet above the ground, how wide is the \r\n% alley?\r\n\r\n%% Eight variables\r\n% The lengths of the ladders are denoted by $a$ and $b$.\r\n% The height of the crossing is $c$.\r\n% The heights of the points where the ladders reach the walls\r\n% are $x$ and $y$.\r\n% The bases of the right triangles whose common height is the\r\n% crossing are $u$ and $v$.\r\n% Finally, the width of the alley is $w$.\r\n% Here is the picture.\r\n\r\n   ladders_diagram('vars')\r\n   \r\n   \r\n%% The equations\r\n% These eight variables are connected by five equations.\r\n% The Pythagorean Theorem provides two equations.\r\n%\r\n% $$ a^2 = x^2 + w^2 $$\r\n\r\n%%\r\n% $$ b^2 = y^2 + w^2 $$\r\n\r\n%%\r\n% The ratios between sides of similar triangles provide two more.\r\n%\r\n% $$ \\frac{x}{w} = \\frac{c}{v} $$\r\n\r\n%%\r\n%\r\n% $$ \\frac{y}{w} = \\frac{c}{u} $$\r\n\r\n%%\r\n% The fifth equation is a simple linear relation that ties the two\r\n% triangles together.\r\n%\r\n% $$ w = u + v $$\r\n\r\n%%\r\n% Five equations involving eight variables leaves three degrees of freedom.\r\n% In principle we could specify any three of the variables and solve for\r\n% the other five.  But that may or may not be easy.\r\n% We will have two different situations in what follows.  The puzzle\r\n% posed in the opening paragraph specifies $a$, $b$ and $c$, and asks\r\n% to find $w$.  This is nontrivial.  On the other hand,\r\n% our graphic app is driven by $x$, $y$ and $w$.  When these three\r\n% are pinned down by mouse clicks, the other five follow immediately.\r\n\r\n%% Harmonic mean\r\n% Combining the last three equations generates an elegant relation.\r\n% This isn't a new equation; it's a consequence of the ones we already\r\n% have.\r\n%\r\n% $$ \\frac{1}{c} = \\frac{1}{x} + \\frac{1}{y} $$\r\n\r\n%%\r\n% This says that the height of the crossing is one-half of the\r\n% _harmonic mean_ of the heights of the two ladders.\r\n% The equation is a familiar one in _optics_, where it is known as\r\n% the _thin lens equation_.  It relates the location of an image to\r\n% the object distance and focal length.\r\n\r\n%% Smallest integer solution\r\n% The following picture shows a solution of these equations where all eight\r\n% variables have integer values.  In fact, if we collect all eight\r\n% variables into a vector $s$.\r\n%\r\n% $$ s = [a, b, c, u, v, w, x, y] $$\r\n%\r\n% And use the 1-norm to measure the \"size\" of a solution.\r\n%\r\n% $$ ||s||_1 = \\sum_{i=1}^8 s_i $$\r\n%\r\n% Then ITOT (\"It Turns Out That\") this is smallest solution with\r\n% all integer elements.\r\n   \r\n   ladders_diagram('vals')\r\n\r\n%% Puzzle\r\n% Combining Pythagoras and optics provides a single nonlinear equation\r\n% for $w$ in terms of $a$, $b$ and $c$.\r\n%\r\n% $$ \\frac{1}{\\sqrt{a^2 - w^2}}+\\frac{1}{\\sqrt{b^2 - w^2}}=\\frac{1}{c} $$\r\n\r\n%%\r\n% It is not difficult to use the one-dimensional MATLAB zero finder\r\n% |fzero| with fixed values for |a|, |b| and |c| to compute a solution\r\n% of this equation.\r\n\r\n   a = 30;\r\n   b = 20;\r\n   c = 10;\r\n   F = @(w) 1.\/sqrt(a^2 - w.^2) + 1.\/sqrt(b^2 - w.^2) - 1\/c\r\n   w = fzero(F,c)\r\n   \r\n%%\r\n% So this is the answer to the puzzle.  For the prescribed values\r\n% of the lengths of the ladders and the height of the crossing point,\r\n% the width of the alley has to be about |12.3| feet.\r\n\r\n%%\r\n% A graph of |F(w)| in the vicinity of its zero shows why |fzero| has\r\n% no trouble.\r\n\r\n   ezplot(F,[10,15])\r\n   set(gca,'xaxislocation','origin')\r\n   line(w,0,'marker','.','markersize',24,'color','k')\r\n   \r\n%% The gorilla in the room\r\n% It is easy to solve our single nonlinear equation numerically to\r\n% compute $w$, but to find an analytic solution is a formidable\r\n% challenge, even for computer algebra systems.  Historically, the\r\n% approach has focused on an equivalent quartic polynomial.\r\n\r\n%%\r\n% Take $a = 40$, $b = 30$ and $c = 20$.  Let\r\n%\r\n% $$ z = w^2 $$\r\n%\r\n% Multiply through by the expressions in the denominators to put\r\n% everything on one level.\r\n%\r\n% $$ 10\\, \\sqrt{400 - z} + 10\\, \\sqrt{900 - z} = \\sqrt{400 - z}\\, \\sqrt{900 - z} $$\r\n\r\n%%\r\n% Now square both sides to get rid of the sqrt's on the right.  Then\r\n% rearrange terms and square everything again to eliminate the remaining\r\n% sqrt's. If you're careful, you will eventually reach a polynomial of\r\n% degree 4 in $z$.\r\n%\r\n% $$ z^4 - 2200\\, z^3 + 1630000\\, z^2 - 454000000\\, z + 38500000000 = 0 $$\r\n\r\n%%\r\n% But we're only halfway there.  We still have to solve this quartic.\r\n% In principle it is possible to do this analytically, but let's again\r\n% abandon algebraic and resort to numeric techniques.\r\n\r\n   poly = [ 1, -2200, 1630000, -454000000, 38500000000];\r\n   z = roots(poly)\r\n   \r\n%%\r\n% The repeated squaring has produced extraneous roots.  ITOT that we can\r\n% recover $w$ from the fourth one.\r\n\r\n   w = sqrt(z(4))\r\n   \r\n%%\r\n% It is reassuring to find the same width.\r\n     \r\n%% Ladders App\r\n% I am having a lot of fun with an interactive graphical\r\n% experience where you vary any one of four parameters and see how\r\n% it affects the others.  You can change the height of\r\n% the points where the ladders hit the wall, or change the\r\n% width of the alley.  You will find that dragging any one of these three\r\n% control points affects only a couple of the other quantities.\r\n\r\n%%\r\n% You will see more action when you vary the crossing point.  This\r\n% changes all of the values except the width.  Of course, it is\r\n% not physically realistic to expect to alter the lengths of\r\n% the ladders by changing where they cross, but that would actually\r\n% have to happen if they were constrained to meet the walls.\r\n\r\n %%\r\n% The complete program for this app is the subject for my blog in two\r\n% weeks.  The title is\r\n% \"Investigating the Classic Crossed Ladders Puzzle\".\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2016\/03\/14\/investigating-the-classic-crossed-ladders-puzzle\r\n% This link> should be good after March 14.\r\n%\r\n% <<ladders_movie.gif>>\r\n\r\n%% Acknowledgement\r\n% Thanks to Ned Gulley of MathWorks for suggesting that this classic\r\n% puzzle warrants another look.\r\n\r\n##### SOURCE END ##### 9d7b0418c4904be7a546ded01ffedeb9\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/ladders_blog_01.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>Here is a classic puzzle. A pair of ladders leaning against the sides of an alley form a lopsided cross.  Each ladder is propped against the base of one wall and leans against the opposite wall. If one ladder is 30 feet long, the other 20 feet long, and the point where they cross 10 feet above the ground, how wide is the alley?... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2016\/02\/29\/the-classic-crossed-ladders-puzzle\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,4,20],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1349"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=1349"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1349\/revisions"}],"predecessor-version":[{"id":1356,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1349\/revisions\/1356"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=1349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=1349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=1349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}