# Optimization explained to a middle school kid

Let's say you play the game of collecting the maximum amount of coins along a path in the $$(x,y)$$ plane. The total amount of coins collected $$S$$ is given by $$S = 5x + 7y$$ where $$5$$ and $$7$$ represents the number of coins collected by walking respectively one unit in the $$x$$ and $$y$$ direction. However I can only go as far as one unit of distance ($$x^2+y^2=1$$).

It turns out that the solution to the problem is so such that $$y/x = 7/5$$ or said in other words, the ratio of how much you have to walk in the $$y$$ direction compared to in the $$x$$ direction is the same as the ratio of the rates at which you collect the coins in the $$y$$ direction compared to in the $$x$$ direction.

My question : suppose I have to explain this result to a middle school student who does not know any calculus of trigonometry. He is also quite shaky on describing equations of lines in the plane so I would not rely on that. How can I convince him with intuition that the two ratios are the same? (I'm not looking for a series of algebraic equations but rather for some kind of a visual proof).

• Is this specific example important, or would it be helpful if we suggested examples that don't require as much preexisting knowledge? – Ray Sep 25 '18 at 19:46
• The problem is that at a certain point you have to explain why there's some sort of a connection between ratios and circles, which is just sort of fundamentally non-trivial. The real reason this happens is because of the specific way in which the slope of a circle changes as a function of height. I don't see how you're going to do this without the equation $x^2+y^2=1$ showing up in some form or another. – Jack M Sep 25 '18 at 23:33
• This is a bad example, because we're supposed to be picking up coins along a path, but the objective function makes no sense in terms of actual coins being physically located somewhere on the path. We can end up with negative coins or fractional coins, and two paths to the same endpoint produce the same number of coins no matter what. – user2357112 Sep 26 '18 at 2:51
• Optimally, you end up with $\sqrt{74}$ coins. Do you really want to get into an argument with a middle schooler about what it means to have $\sqrt{74}$ coins while you're trying to talk about optimization problems? – user2357112 Sep 26 '18 at 2:57
• What exactly are you trying to teach? What reusable principle/technique? What practically applicable definition of "optimization"? The way to "explain this result" is to apply/use the definition in a piece of reasoning. The only "intuition" needed should be to accept/understand definitions. What then is the specification, expressed in defined terms? "as far as one unit of distance" is not clear. You then say "(x²+y²=1)" but don't relate them--still not clear. "lines in the plane"--you mean it's a straight line path? Where's "optimize"? Get the premises clear before worrying about a solution. – philipxy Sep 26 '18 at 6:25

First of all, let's lose the coins. That doesn't make any sense. How can the number of coins you get be somehow related to the direction in which you walk? Surely if there are coins lying around on the ground, the amount you get should be proportional to how far you walk, not in what direction.

Maybe the following is a better visualization of the problem. You are inside a circular wall, with some large radius, say a mile. Every step you take east, I'll pay you 5 gold. Every step you take north, I'll pay you 7 gold. How can you maximize the amount of money you make?

Where you end up and how much money you make are functions only of how many steps east and how many steps north you take. It doesn't matter in what order you take them. Therefore, we may as well begin by stepping only north, and then step only east until we hit the wall. So the only question is when to stop going north and go east.

At first it seems like we should just only go north, since we get more money that way. But towards the end of our journey, when we're just one step away from the wall, if we look to our right we'll find that we can step several steps to the east before hitting the wall. So clearly at that point we should head east. So it's not hard to intuitively see why going only north isn't optimal.

That's the easy part.

But now we need to work out exactly when to turn east. The basic idea is that every step I take north, I'm sacrificing a certain number of steps east. Because of the way the circle is getting shallower and shallower as I go north, (the eastern wall is approaching me faster and faster), I'm sacrificing more and more as I go north. How much eastward distance I sacrifice on a given step north has to do with the slope of the circle.

When we take a step north and sacrifice $$x$$ steps east, we gain a net total of $$7-5x$$ gold, which becomes negative at the point $$x=\frac75$$. By zooming into the circle and applying properties of similar triangles, it should be possible to essentially reinvent enough of differential calculus to show what you're trying to prove.

• +1 Yeah the coins don't make any sense to me either – Ovi Sep 26 '18 at 3:31
• I very like the way you pose the problem and the visualization of it. Your last comment on applying similar triangle is a very good idea! It reminds me of an excellent video of 3blue1brown (youtu.be/S0_qX4VJhMQ?t=14m51s) where he does a similar construction in order to show what the derivative $sin(\theta)$ is. Brilliant! – Corvinus Sep 26 '18 at 12:58

I'd probably start with easier numbers to visualise. For example $$10$$ and $$5$$, you can explain that every step in $$1$$ direction you pick up $$£5$$, and every step in the other you pick up $$£10$$. Therefore to collect the same amount of money in the first direction as the second you have to walk twice as fast (or far). Hopefully this can start the intuitive thinking about the relationship between the ratios.

• I'm no mathematician, but after some thought about the question and then scrolling down, I think your answer matches my own conclusion fairly well. Tying it to Money definitely improves on my train of thought! – Ruadhan2300 Sep 25 '18 at 12:37
• @Ruadhan2300 Thank you! And quite clearly I agree. Bombardment with graphs and equations confuses so many people trying learn maths, but everyone understands money (at least to a certain extent) – MRobinson Sep 25 '18 at 12:48
• I was framing it in terms of energy-usage and how steep a hill is, essentially the steeper the hill the harder it is to climb, so the more energy you'd have to use to travel the same distance. – Ruadhan2300 Sep 25 '18 at 12:50
• @Ruadhan2300 ah nice, I like that as well, just anything to make it not maths! – MRobinson Sep 25 '18 at 12:56
• Then the kid says "Ok, so always walk in the 10 direction to get the most money!" I don't think this is much of an answer to the question, it leaves the hard part undone. – usul Sep 25 '18 at 18:28

I know you said to perhaps avoid equations of lines, but I think the lines here are a crucial point. You don't need to "know" how to plot them though, just somehow convince yourself that the following description makes sense.

Try to draw the set of points in the positive quadrant where $$S = 1$$. This should be easy to do for the intercepts $$(1/5, 0)$$ and $$(0, 1/7)$$, and then work out that everything on the line between them also has $$S = 1$$. Now try again for $$S = 2$$, which has intercepts $$(2/5, 0)$$ and $$(0, 2/7)$$, and so on. What you find is that increasing $$S$$ corresponds to making this triangle larger and larger, but always in the same horizontal:vertical ratio of $$7:5$$.

The key thing to take away from this is that all the points having the same $$S$$ are a line, and increasing this $$S$$ is just sliding this line to be a higher parallel line.

Now we include the constraint that $$x^2 + y^2 = 1$$, i.e. we want to only look at points lying on the unit circle. Trying to maximise $$S$$ while still having $$(x, y)$$ lying on the circle means that you will slide the triangle to make it larger and larger until the line just touches the edge of the circle, i.e. the line is tangent to the circle. (It's also interesting here that for a suboptimal $$S$$, there are two solutions - this could make for some interesting discussion). You make a picture like the following:

where the outer triangle $$ADE$$ is in the ratio $$7:5$$, and the angle $$ABE$$ is a right angle because tangents to circles meet the diameter at right angles. The point $$B$$ is the point achieving the maximum. Now all you need to explain is why the smaller triangle $$ACB$$ is in the ratio $$5:7$$, which can be done in several ways (if $$m$$ is a gradient, the perpendicular gradient is $$-1/m$$, etc etc).

This is related in an interesting way to the method of Gradient Descent:

• Why is it that if you find yourself on a 2D-plane tilted by a slope of $$a$$ in the $$x$$-direction and a slope of $$b$$ in the $$y$$-direction, the steepest uphill direction will be toward $$(a,b)$$?

I have no idea how you would convince someone without going into at least some mathematical details, but from my perspective I have the following reasons:

1. If one moves perpendicular to the $$v=(5,7)$$ vector, which would be toward $$\hat v=(-7,5)$$ you would gain zero score from the expression $$5x+7y$$. Simply we have $$5\cdot(-7)+7\cdot 5=0$$.
2. Any direction can be decomposed into two parts in terms of the two perpendicular directions $$v=(5,7)$$ and $$\hat v=(-7,5)$$, and only the part in direction of $$v$$ will increase the score.

Good luck breaking this down and coming up with a visual representation of it. I am positive it can be done, but I am less sure how you would omit any of the non-intuitive details.

At least you can say that the part of "some direction" pointing in the direction of $$v$$ is shorter than "some direction" itself, and so it achieves the same score while traversing a shorter distance. The red dotted line represents the part of "some direction" not contributing to the score at all.

Consider the iso-$$S$$ curves, i.e. the combinations of $$x$$ and $$y$$ giving the same amount.

If you increase $$x$$ by $$7$$, you'll have to decrease $$y$$ by $$5$$ to ensure status-quo. As this is true whatever $$x,y$$, the iso-$$S$$ are straight lines of direction $$(7,-5)$$.

Now it should be clear that the optimal solution is found on the iso-$$S$$ that is tangent to the circle.

And as a tangent at a point is perpendicular to the corresponding radius, the point of contact is found in the perpendicular direction. Rotate the vector $$(7,-5)$$ to get $$(5,7)$$, giving the slope of the perpendicular.

You could start by showing that if you're walking along the line $$7y=5x$$,then going to the upper right increases the number of coins, while walking to the lower left decreases it. Then show how walking a little bit off the line to the upper right increases coins, but not as quickly. As your path has a larger and larger angle, the rate decreases. Eventually, when it reaches 90 degrees, you aren't getting any more coins, and when the angle exceeds that, you're losing coins. Tell the student to imagine walking along the circle, and holding their arm straight out pointing forward. When will their arm go from pointing in an "increasing" direction to a "decreasing" direction? That's where the number of coins is maximized.

You could try a change of coordinates. Mark a tick mark off every 1/7 of a y unit, and every 1/5 of an x unit. You get a coin at each tick mark. What happens if you redraw the graph so that each tick mark is equidistant? The circle turns into an ellipse. If you draw the point that corresponds to $$(\sqrt2,\sqrt2)$$, then even though calculating the exact optimum location will be difficult, it'll be obvious that it's to the left and above that point, showing that giving more coins for vertical distance moves the optimum point to the left and up.