Throwing a javelin and finding where it lands
Tags: highschool, maths, python
Published: 2024-07-13 14:26:07

---
title: Throwing a javelin and finding where it lands
published: true
date: 2024-07-01 22:00:00 UTC
tags: Highschool,Maths,Python
canonical_url: https://peateasea.de/throwing-a-javelin-and-finding-where-it-lands/
cover_image: https://peateasea.de/assets/images/javelin-throw.png
---

*Originally published on [peateasea.de](peateasea.de/throwing-a-javelin-and-finding-where-it-lands/).*

As part of tutoring physics and maths to high school students, I sometimes write up [deep-dive explanations](https://github.com/paultcochrane/after-school-help) of questions arising during lessons. Below I discuss the example of throwing a javelin, working out where it will hit the ground, and what its highest point will be.

We’ve been given the following problem to solve:

* * *

The flight path of a javelin (excluding the effects of air resistance) can be described by the function {% katex inline %}f(x) = -0.0265 x^2 + x + 2{% endkatex %}, where {% katex inline %}x{% endkatex %} describes the horizontal distance (in metres) from the point where the javelin was thrown and {% katex inline %}f(x){% endkatex %} describes the height of the javelin above the ground (also in metres).

- a) determine the point at which the javelin hits the ground.
- b) determine the highest point of the javelin’s path.
- c) determine the distance and highest point when the path is described by {% katex inline %}f(x) = -0.03 x^2 + x + 2{% endkatex %}.

* * *

Let’s begin by visualising the function.

## Plotting the function

Plotting the curve corresponding to a function is a good way to build an intuition about the problem at hand. Computers are good at plotting data, so let’s use some [Python](https://www.python.org/) code in a [Jupyter notebook](https://jupyter.org/) to plot the function {% katex inline %}f(x){% endkatex %}.

Start a Jupyter notebook and enter the following code into it.

```python
import numpy as np # import the numerical libraries and give them the name "np"
import matplotlib.pyplot as plt # import the plotting libraries and give them the name "plt"

# define the function we want to plot
# this uses the general form of a parabola: a x^2 + b x + c
def f(x, a=-0.02625, b=1, c=2):
    return a*x**2 + b*x + c

# define a range of x points (which we call "xs" here) from 0 to 50 metres in steps of 0.1 m
xs = np.arange(0, 50, 0.1)
# determine the values on the y-axis from the function f(x) which we defined above (which we call "fs" here)
fs = [f(x) for x in xs]

fig, ax = plt.subplots() # set up the plot
# set the axes labels and plot title
ax.set_xlabel('x (m)')
ax.set_ylabel('f(x) (m)')
ax.set_title('A javelin throw')
# plot the data
ax.plot(xs, fs)
# add a grid to the plot to more easily see the function's values
plt.grid()
# show the plot
plt.show()
```

Running this code gives the following plot:

![Plot of the curve for f1(x)](https://peateasea.de/assets/images/throwing-a-javelin-function-curve-1.png)

Try changing some of the values within your Jupyter notebook and then select “Run selected cell” from the “Run” menu to see how the function’s shape changes.

Note that I guessed the range of {% katex inline %}x{% endkatex %} values; it was clear from the question that the values should start at 0, but the value of 50 was a plain guess.

Now that we’ve plotted the function, some things become more obvious. The javelin is thrown from some initial non-zero height above the ground (i.e. the curve doesn’t cross the {% katex inline %}y{% endkatex %}-axis at 0). This makes sense because someone throwing the javelin will be holding it in their hand above their head and this will be some positive value. We can work out exactly what this value is by setting {% katex inline %}x = 0{% endkatex %} (the javelin’s starting point) in the equation for the function:

{% katex %}
f(0) = -0.02625 \cdot 0^2 + 0 + 2 = 2 m
{% endkatex %}

In other words, the javelin is held 2 m above the ground when it is let go.

The curve gives us more information: it crosses the {% katex inline %}x{% endkatex %}-axis (where {% katex inline %}y = 0{% endkatex %}) at approximately 40 m distance. This gives us an estimate of the answer for part (a) of the question. The negative “height” values in the plot are because I chose {% katex inline %}x{% endkatex %} values from 0 to 50 and from roughly 40 m up to 50 m the function is negative. Clearly this this isn’t a physically logical situation (I mean, the javelin would have had to hit the ground _very hard_ for it to go almost 15 m below ground level!), so we can ignore the negative {% katex inline %}f(x){% endkatex %} values in this upper range.

One thing that the plot hints at but doesn’t explicitly display is that we could extend the curve in the _negative_ {% katex inline %}x{% endkatex %} direction to see where the javelin might have come from had it started its trajectory from ground level. After all, we can equally well put negative {% katex inline %}x{% endkatex %} values into {% katex inline %}f(x){% endkatex %} as we can positive {% katex inline %}x{% endkatex %} values.

Now that we’ve got some intuition about the problem at hand, let’s start solving things exactly.

## Determining the point at which the javelin hits the ground

There are two equivalent ways to solve this problem. Which path you choose depends upon where you live.

Honestly! Let me explain.

In English-speaking countries, it is common to use the [quadratic formula](https://en.wikipedia.org/wiki/Quadratic_formula) to find the roots of a quadratic equation (which is what we need to do here; see later). I live in Germany, and the quadratic formula isn’t taught in schools here. Instead, high-school students are taught the [p-q formula](https://de.wikipedia.org/wiki/Quadratische_Gleichung#L%C3%B6sungsformel_f%C3%BCr_die_Normalform_(p-q-Formel)), which amounts to the same thing as the quadratic formula. The p-q formula results from solving the [reduced quadratic equation](https://en.wikipedia.org/wiki/Quadratic_equation#Reduced_quadratic_equation) for reasons that I will explain below. For completeness, I’m going to mention both methods here. Let’s call the two root-finding methods “the English way” and “the German way” respectively.

### “The English way”

If we rewrite the function {% katex inline %}f(x){% endkatex %} in its general form, we have

{% katex %}
f(x) = a x^2 + b x + c
{% endkatex %}

In the case we’re discussing here, the parameters {% katex inline %}a{% endkatex %}, {% katex inline %}b{% endkatex %} and {% katex inline %}c{% endkatex %} are: {% katex inline %}a = -0.02625{% endkatex %}, {% katex inline %}b = 1{% endkatex %} and {% katex inline %}c = 2{% endkatex %}.

Note that the coefficient {% katex inline %}a{% endkatex %} is negative: this means that as {% katex inline %}x{% endkatex %} increases, the parabola rises to a maximum and then decreases again. Because mathematicians love giving such concepts names, this is called a [concave_function](https://en.wikipedia.org/wiki/Concave_function). A positive value of {% katex inline %}a{% endkatex %} would make the function curve downwards to a minimum and then curve upwards again (which is then called a [convex_function](https://en.wikipedia.org/wiki/Convex_function)). Try changing the value of {% katex inline %}a{% endkatex %} in the Python code you entered into your Jupyter notebook above to see what effect changing its sign has.

To find out where the javelin hits the ground, we need to work out when {% katex inline %}f(x){% endkatex %} is equal to zero (i.e. at ground level). This is the same thing as working out where the curve from the plot above crosses the {% katex inline %}x{% endkatex %} -axis. Note that because the function is a [parabola](https://en.wikipedia.org/wiki/Parabola) (i.e. a [polynomial](https://en.wikipedia.org/wiki/Polynomial) of degree 2) this will happen in two places: one at the end of the javelin’s path of flight and one _behind_ where the javelin was let go. Note that a function merely models a physical situation, it doesn’t have to _always_ match physical reality. After all, one doesn’t talk about negative distances on a day-to-day basis. Remember: [all models are wrong, but some models are useful](https://en.wikipedia.org/wiki/All_models_are_wrong)).

Finding where a function crosses the {% katex inline %}x{% endkatex %} -axis is also called _[finding the roots of a function](https://en.wikipedia.org/wiki/Zero_of_a_function)_ where a _root_ is a value of {% katex inline %}x{% endkatex %} where {% katex inline %}f(x) = 0{% endkatex %}.

Because the function {% katex inline %}f(x){% endkatex %} is a polynomial of degree 2 (its largest exponential is a 2) this is also called a [quadratic equation](https://en.wikipedia.org/wiki/Quadratic_equation). There is a known solution for the roots of a quadratic equation which is (confusingly, I find) known as the [quadratic formula](https://en.wikipedia.org/wiki/Quadratic_formula):

{% katex %}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
{% endkatex %}

This formula gives us two values, one of which is where the javelin hits the ground. Let’s call the two values {% katex inline %}x_1{% endkatex %} and {% katex inline %}x_2{% endkatex %} respectively:

{% katex %}
x_1 = \frac{-b + \sqrt{b^2 - 4ac}}{2a}
{% endkatex %}

and

{% katex %}
x_2 = \frac{-b - \sqrt{b^2 - 4ac}}{2a}
{% endkatex %}

We can plug our {% katex inline %}a{% endkatex %}, {% katex inline %}b{% endkatex %} and {% katex inline %}c{% endkatex %} values into this equation within our Jupyter notebook. Doing so, we get code like this:

```python
a = -0.02625
b = 1
c = 2

x1 = (-b + np.sqrt(b**2 - 4*a*c))/(2*a)
x2 = (-b - np.sqrt(b**2 - 4*a*c))/(2*a)

print(f"x_1 = {x1:.3f} m and x_2 = {x2:.3f} m")
```

Running the code gives this output:

```
x_1 = -1.905 m and x_2 = 40.000 m
```

In other words, the javelin hit the ground after 40 m. The value for {% katex inline %}x_1{% endkatex %} is negative which tells us that it’s a position _behind_ the person throwing the javelin. We can disregard this solution because it doesn’t make physical sense. The javelin thrower didn’t throw the javelin backwards _as well as_ forwards.

### “The German way”

As mentioned earlier, high-school students solve this kind of problem differently in Germany. They use what is called the [p-q formula](https://de.wikipedia.org/wiki/Quadratische_Gleichung#L%C3%B6sungsformel_f%C3%BCr_die_Normalform_(p-q-Formel)) which we get by solving the [reduced quadratic equation](https://en.wikipedia.org/wiki/Quadratic_equation#Reduced_quadratic_equation). Why the _reduced_ quadratic equation? Well, if we can make the factor of the quadratic term (i.e. the {% katex inline %}x^2{% endkatex %} term) equal 1, then we only need to worry about the factor of the linear term (i.e. the {% katex inline %}x{% endkatex %} term) and the constant (the term without any {% katex inline %}x{% endkatex %}-related part). This means we only need to consider two parameters when calculating the zeros of a quadratic equation instead of three parameters. This might not sound like much of a win, but I guess it helps. I’ll show you what I mean.

Let’s take the general form of a quadratic function:

{% katex %}
f(x) = a x^2 + b x + c
{% endkatex %}

we know that we want to find solutions to this equation when it is equal to zero, i.e.

{% katex %}
a x^2 + b x + c = 0
{% endkatex %}

We can simplify things a little bit by dividing both sides of this equation by {% katex inline %}a{% endkatex %}:

{% katex %}
x^2 + \frac{b}{a} x + \frac{c}{a} = 0
{% endkatex %}

Hrm, those factors of {% katex inline %}\frac{b}{a}{% endkatex %} and {% katex inline %}\frac{c}{a}{% endkatex %} look complicated. Let’s rename them. Let’s set {% katex inline %}\frac{b}{a} = p{% endkatex %} and {% katex inline %}\frac{c}{a} = q{% endkatex %}. Substituting these values into the equation above we get

{% katex %}
x^2 + p x + q = 0
{% endkatex %}

which is known as the reduced quadratic equation because we _reduced_ the number of parameters from 3 to 2. The solution to this new form of the quadratic equation is

{% katex %}
x = -\frac{p}{2} \pm \sqrt{\left(\frac{p}{2}\right)^2 - q}
{% endkatex %}

and this is the famous p-q formula. This formula is so famous in Germany, that there’s even a [song about it](https://www.youtube.com/watch?v=tRblwTsX6hQ).

Let’s stop talking about this thing and use it. Remember that the function we’ve been given is

{% katex %}
f(x) = -0.02625 x^2 + x + 2
{% endkatex %}

This isn’t in a form we can use for the p-q formula. Remember that we want to find the points where this function is equal to zero, hence we can rewrite this as

{% katex %}
-0.02625 x^2 + x + 2 = 0
{% endkatex %}

We can now divide both sides by {% katex inline %}-0.02625{% endkatex %} to get

{% katex %}
x^2 - \frac{x}{0.02625} - \frac{2}{0.02625} = 0
{% endkatex %}

This equation is now in the form we need for the p-q formula, where {% katex inline %}p = -\frac{1}{0.02625}{% endkatex %} and {% katex inline %}q = -\frac{2}{0.02625}{% endkatex %}. Plugging these values into the formula within our Jupyter notebook we get:

```python
p = -1/0.02625
q = -2/0.02625

x1_pq = -p/2 + np.sqrt((p/2)**2 - q)
x2_pq = -p/2 - np.sqrt((p/2)**2 - q)

print(f"x_1 = {x1_pq:.3f} m and x_2 = {x2_pq:.3f} m")
```

where I’ve added the suffix `_pq` to the `x1` and `x2` variables to highlight that these have been calculated via the p-q formula.

Running this code produces this output:

```
x_1 = 40.000 m and x_2 = -1.905 m
```

In other words, we get the same result as before when using “the English way”, but this time {% katex inline %}x_1{% endkatex %} is the positive value (and hence where the javelin hits the ground) and {% katex inline %}x_2{% endkatex %} is the negative value (the zero of the function behind the javelin thrower).

I don’t know if this is an easier or clearer way to do things, but it gives the same result. You just have to remember to divide everything by the factor of the quadratic term (i.e. the {% katex inline %}x^2{% endkatex %} bit) before working out what {% katex inline %}p{% endkatex %} and {% katex inline %}q{% endkatex %} are.

### Taking the long way round

While explaining this problem to a student recently, I kept having the feeling that there was something special about the value {% katex inline %}0.02625{% endkatex %}. I mean, it seemed “clean”, “round” or “regular” in some kind of way; like it could be the square of some number or perhaps it has some kind of special form that wasn’t obvious from the decimal representation. Also, I felt that this number must be special in some way otherwise the distance the javelin was thrown wouldn’t be _exactly_ 40 m. Although I couldn’t spot anything special during the lesson, it kept bugging me. After the lesson, I worked out what was special _and_ I worked out that it wasn’t necessary to use a calculator (or Python) to work out how far the javelin flew.

What was special about the number was that it can be written as a fraction. I.e. it turns out that

{% katex %}
0.02625 = \frac{21}{800}
{% endkatex %}

Admittedly, I needed to use a computer algebra system such as [Sage](https://www.sagemath.org/) to find the fraction,<sup id="fnref:sagemath-simplest-rational" role="doc-noteref"><a href="#fn:sagemath-simplest-rational" rel="footnote">1</a></sup> but once you know what the fraction is, it’s no longer necessary to use a calculator. In the end, the calculation wasn’t that much simpler, but I found it interesting, so let’s look at it.

Our function now looks like this

{% katex %}
f(x) = -\frac{21}{800} x^2 + x + 2
{% endkatex %}

in its “fractional form”.

The first thing to note is that it won’t be any fun writing {% katex inline %}\frac{21}{800}{% endkatex %} all over the place, so let’s replace this value with the symbol {% katex inline %}d{% endkatex %}. The function is now:

{% katex %}
f(x) = -d x^2 + x + 2
{% endkatex %}

We want to find when this function is equal to zero, i.e. we want to solve this equation:

{% katex %}
-d x^2 + x + 2 = 0
{% endkatex %}

We also want this in the form required for the p-q formula, so let’s now divide both sides by {% katex inline %}-d{% endkatex %}:

{% katex %}
x^2 - \frac{x}{d} - \frac{2}{d} = 0
{% endkatex %}

This result means that {% katex inline %}p = -\frac{1}{d}{% endkatex %} and {% katex inline %}q = -\frac{2}{d}{% endkatex %}. Plugging these numbers into the p-q formula gives

{% katex %}
x = \frac{1}{2 d} \pm \sqrt{\left(\frac{-1}{2 d}\right)^2 + \frac{2}{d}}
{% endkatex %}

Multiplying out the exponent, we get

{% katex %}
x = \frac{1}{2 d} \pm \sqrt{\frac{1}{4 d^2} + \frac{2}{d}}
{% endkatex %}

If you squint at this equation, you might notice that the {% katex inline %}4 d^2{% endkatex %} in the denominator under the square root could potentially be factored out. Its square root would give a factor of {% katex inline %}\frac{1}{2d}{% endkatex %} in front of the square root, which is also the first term of the equation. That hints at more possible simplifications. Let’s do that.

First, let’s put the two terms under the square root over a common denominator of {% katex inline %}4 d^2{% endkatex %} by multiplying the second term (i.e. {% katex inline %}\frac{2}{d}{% endkatex %}) by {% katex inline %}\frac{4 d}{4 d}{% endkatex %}:

{% katex %}
x = \frac{1}{2 d} \pm \sqrt{\frac{1}{4 d^2} + \frac{8 d}{4 d^2}}
{% endkatex %}

This simplifies a bit to:

{% katex %}
x = \frac{1}{2 d} \pm \sqrt{\frac{1 + 8 d}{4 d^2}}
{% endkatex %}

which we can now write as

{% katex %}
x = \frac{1}{2 d} \pm \frac{\sqrt{1 + 8 d}}{\sqrt{4 d^2}}
{% endkatex %}

As you can see {% katex inline %}\sqrt{4 d^2} = 2d{% endkatex %}, hence

{% katex %}
x = \frac{1}{2 d} \pm \frac{\sqrt{1 + 8 d}}{2 d}
{% endkatex %}

Extracting the factor of {% katex inline %}\frac{1}{2d}{% endkatex %}, we get

{% katex %}
x = \frac{1}{2 d} \left(1 \pm \sqrt{1 + 8 d}\right)
{% endkatex %}

That looks a bit easier to handle. Let’s now substitute our value for {% katex inline %}d = \frac{21}{800}{% endkatex %}:

{% katex %}
x = \frac{800}{42} \left(1 \pm \sqrt{1 + \frac{8 \times 21}{800}}\right)
{% endkatex %}

We can get rid of at least a factor of 8 within the square root to simplify things a bit

{% katex %}
x = \frac{800}{42} \left(1 \pm \sqrt{1 + \frac{21}{100}}\right)
{% endkatex %}

Putting the terms under the square root over a common denominator, we get

{% katex %}
x = \frac{800}{42} \left(1 \pm \sqrt{\frac{100 + 21}{100}}\right)
{% endkatex %}

which is

{% katex %}
x = \frac{800}{42} \left(1 \pm \sqrt{\frac{121}{100}}\right)
{% endkatex %}

The square root of 100 is 10, so we can extract a factor of {% katex inline %}\frac{1}{10}{% endkatex %} from the square root

{% katex %}
x = \frac{800}{42} \left(1 \pm \frac{1}{10} \sqrt{121}\right)
{% endkatex %}

Hrm, {% katex inline %}\sqrt{121}{% endkatex %} looks strangely familiar. Hey, it’s just 11 (i.e. {% katex inline %}11 \times 11 = 121{% endkatex %})! That’s cool! We can get rid of that nasty square root now:

{% katex %}
x = \frac{800}{42} \left(1 \pm \frac{11}{10}\right)
{% endkatex %}

Using a common denominator again, we have

{% katex %}
x = \frac{800}{42} \left(\frac{10 \pm 11}{10}\right)
{% endkatex %}

Cancelling out the factor of 10, we get

{% katex %}
x = \frac{80}{42} \left(10 \pm 11\right)
{% endkatex %}

The javelin will have been thrown to the larger of the two solutions, in other words, we can take the {% katex inline %}+{% endkatex %} part of the {% katex inline %}\pm{% endkatex %}

{% katex %}
x = \frac{80}{42} \left(10 + 11\right)
{% endkatex %}

which is

{% katex %}
x = \frac{80}{42} \times 21
{% endkatex %}

We now see that 42 is twice 21, so this reduces to

{% katex %}
x = \frac{80}{2}
{% endkatex %}

which is

{% katex %}
x = 40
{% endkatex %}

In other words, the javelin hit the ground after 40 m. Finally! We managed to work out what the value was without a calculator! Ok, so that was a lot of work, but it was somehow satisfying that it wasn’t necessary to use a machine to find the answer.

## Determining the highest point of the javelin’s path (method 1)

If we look at the plot of the function we created earlier, we can see that when the javelin reaches its highest point, the slope of its path is completely flat. Up to that point, the slope of the javelin’s path is pointing upwards and after the highest point, the slope of the javelin’s path is pointing downwards. The slope of a curve at a given point is given by its [tangent](https://en.wikipedia.org/wiki/Tangent). The tangent to a curve at a given point (and hence the curve’s slope at that point) can be determined by taking the [derivative](https://en.wikipedia.org/wiki/Derivative) of the function at that point. For our function {% katex inline %}f(x){% endkatex %}, we can take its derivative and thus find the function’s slope at any given point {% katex inline %}x{% endkatex %} along its path.

You will often see the derivative of a function written as {% katex inline %}f'(x){% endkatex %} or as {% katex inline %}\frac{df}{dx}{% endkatex %}; they mean the same thing. To take the derivative of a power such as {% katex inline %}x^n{% endkatex %}, take the value {% katex inline %}n{% endkatex %} and multiply it by the power reduced by 1, i.e. the derivative of {% katex inline %}x^n{% endkatex %} is {% katex inline %}n x^{n-1}{% endkatex %}. We can apply this rule to our function {% katex inline %}f(x){% endkatex %} term-by-term in the expression.

Thus the derivative of

{% katex %}
f(x) = ax^2 + bx + c
{% endkatex %}

is

{% katex %}
f'(x) = 2ax + b
{% endkatex %}

where we have used the fact that taking the derivative of a constant is zero. A constant doesn’t vary as we change {% katex inline %}x{% endkatex %}, hence its slope is always zero and thus its derivative is zero.

Since we know that the tangent to the function is completely flat at the highest point of the javelin’s path, we can say that the slope at this point is zero. Hence we only need to find the value of {% katex inline %}x{% endkatex %} where the derivative is equal to zero. I.e. we need to solve this equation for {% katex inline %}x{% endkatex %}:

{% katex %}
f'(x) = 0 = 2ax + b
{% endkatex %}

Subtracting {% katex inline %}b{% endkatex %} from both sides of the equation, we get

{% katex %}
-b = 2ax
{% endkatex %}

and dividing both sides of the equation by {% katex inline %}2a{% endkatex %} we find the value of {% katex inline %}x{% endkatex %} when the javelin is at its highest point:

{% katex %}
x = \frac{-b}{2a}
{% endkatex %}

We can do this calculation in our Jupyter notebook by plugging in the values for {% katex inline %}a{% endkatex %} and {% katex inline %}b{% endkatex %} like so:

```python
a = -0.02625
b = 1

x = -b/(2*a)

print(f"x at maximum height is {x:.3f} m")
```

Running this code gives this output:

```
x at maximum height is 19.048 m
```

Does this value make sense? It certainly looks like the highest point occurs at a horizontal distance slightly less than 20 m in the plot of the function we made above. So that’s a good indicator that our answer makes sense.

Also, we found that the javelin hit the ground 40 m. It makes sense that the horizontal distance corresponding to the highest point would be at approximately half that value, i.e. it should be approximately 20 m. Why do we expect the highest point to be at approximately half the thrown distance? Well, a parabola is symmetric across its maximum (or minimum if it is convex). So, if the javelin had been thrown from the point (0, 0) (i.e. from ground level) its highest point would be halfway to where it hit the ground. We expect this distance to be a little bit smaller than 20 m because the javelin is thrown from a height of 2 m above the ground. In a sense, it was already part of the way to its destination when thrown. In other words, yes, the {% katex inline %}x{% endkatex %} distance corresponding to the maximum height of the curve does make sense.

To find the height of the highest point of the javelin’s path, we plug the value we got for the horizontal distance travelled to the javelin’s highest point into our function. I.e., we substitute 19.048 for {% katex inline %}x{% endkatex %} into the function we’re initially given.

{% katex %}
f(19.048) = -0.02625 \cdot 19.048^2 + 19.048 + 2
{% endkatex %}

Converting this into Python within our Jupyter notebook, we have:

```python
print(f"Maximum height is {-0.0265*19.048**2 + 19.048 + 2:.3f} m.")
```

and when we run this, we get:

```
Maximum height is 11.433 m.
```

Therefore the javelin’s maximum height was 11.433 m. Looking back at our [plot of the function from earlier](#plotting-the-function) we see that the maximum is slightly above 10 and is probably some value between 11 and 12, which matches the result we calculated here. Thus we can be confident that the value we calculated is correct.

## Determining the highest point of the javelin’s path (method 2)

We can work out the horizontal distance corresponding to the javelin’s highest point another way. An important point to realise is that a parabola is symmetric along the {% katex inline %}x{% endkatex %}-axis. I.e. half the function lies on one side of the highest point and the other half lies on the other side of the highest point. We can use this property as well as the roots of the equation that we calculated earlier to find the highest point of the javelin’s trajectory. And now we see that it _was_ helpful to calculate the root of the equation behind the thrower!

Using a symmetry of the problem, we now know that the highest point of the javelin’s path is halfway between the two roots. We can calculate the distance between the two roots using our Jupyter notebook by entering the following code.

```python
print(f"The distance between the two roots is: x₂ - x₁ = {x2 - x1:.3f} m.")
```

where we use the `x1` and `x2` values we calculated from “the English way” above.

Running this, we get the following output:

```
The distance between the two roots is: x₂ - x₁ = 41.905 m.
```

The location of the highest point will be half the distance between the two roots plus the position of the point behind the thrower. I.e.:

{% katex %}
\mathrm{highest\ point} = x_1 + \frac{x_2 - x_1}{2}
{% endkatex %}

In other words, we start at {% katex inline %}x_1{% endkatex %} and move forward half of the distance between the two zeros of the function.

We can calculate this in the Jupyter notebook by entering the following code and running it:

```python
print(f"x at maximum height is {(x2 - x1)/2 + x1:.3f} m")
```

Its output is:

```
x at maximum height is 19.048 m
```

which matches the value we got by taking the derivative and finding the point where the slope was equal to zero. Again, since this is the value of {% katex inline %}x{% endkatex %} at the highest point of the javelin’s path, we just need to plug this value into our function.

{% katex %}
f(19.048) = -0.02625 \cdot 19.048^2 + 19.048 + 2
{% endkatex %}

Running the calculation in our Jupyter notebook:

```python
print(f"Maximum height is {-0.0265*19.048**2 + 19.048 + 2:.3f} m.")
```

gives this output:

```
Maximum height is 11.433 m.
```

Which is the result we got earlier. It’s reassuring that by taking different paths we arrive at the same result!

Equivalently, the horizontal distance at the javelin’s highest point will be the position where the javelin hit the ground _minus_ half the distance between the two roots. Using this version of the calculation, we get the same result as above:

{% katex %}
\mathrm{highest\ point} = x_2 - \frac{x_2 - x_1}{2}
{% endkatex %}

where we start at the point {% katex inline %}x_2{% endkatex %} and move _backwards_ half of the distance between the two zeros of the function. In Python:

```python
print(f"x at maximum height is {x2 - (x2 - x1)/2:.3f} m")
```

gives this output:

```
x at maximum height is 19.048 m
```

and equals the two other results for this value that we computed previously. Fairly obviously, if we then plug this value into the function, we get the highest height the javelin reaches, i.e. 11.433 m.

## Determining the distance and highest point when the path is described by {% katex inline %}f(x)=−0.03x^2+x+2{% endkatex %}

This is a very similar question to which we already have an answer. Because of this similarity, it makes sense to compare the two functions with one another:

{% katex %}
f_1(x) = -0.0265 x^2 + x + 2
{% endkatex %}
{% katex %}
f_2(x) = -0.03 x^2 + x + 2
{% endkatex %}

where we’ve labelled the functions according to the order in which they were presented to us in the question.

We can see straight away that there’s only one difference between the two functions: the {% katex inline %}a{% endkatex %} coefficient is a bit more negative in {% katex inline %}f_2(x){% endkatex %}. What does this tell us about the values the function will take? Because the quadratic term has a more negative coefficient, we would expect the height to be lower than in the initial example and the distance to be less. Why? Well, the more negative value will “put pressure” on the function to come down sooner than the function in the first part of the exercise.

Let’s plot the function to see if our intuition is correct. Enter the following code into your Jupyter notebook

```python
# we've already imported the numerical and plotting libraries earlier, hence we don't need to do this again

# we've also defined the function to plot in a general way earlier;
# we just need to specify the "a" value when generating the list of "fs" this time

# define a shorter list of x points from 0 to 40 metres in steps of 0.1 m
xs = np.arange(0, 40, 0.1)
# determine the values on the y-axis from the function f(x) with the updated "a" value
fs = [f(x, a=-0.03) for x in xs]

fig, ax = plt.subplots() # set up the plot
# set the axes labels and plot title
ax.set_xlabel('$x$ (m)')
ax.set_ylabel('$f_2(x)$ (m)')
ax.set_title('A second javelin throw')
# plot the data
ax.plot(xs, fs)
# add a grid to the plot to more easily see the function's values
plt.grid()
# show the plot
plt.show()
```

and run it. You should see something like this:

![Plot of the curve for f2(x)](https://peateasea.de/assets/images/throwing-a-javelin-function-curve-2.png)

This result matches our intuition: the distance thrown seems to be approximately 35 m this time; less than the distance from part (a). The highest point looks to occur at a horizontal distance of approximately 17 m, also slightly less than our answer from part (a).

Let’s work out the distance travelled using both the “English” and “German” ways.

### Finding the distance the “English” way

Using the quadratic formula again to work out at which {% katex inline %}x{% endkatex %} values {% katex inline %}f_2(x){% endkatex %} is zero, we have:

{% katex %}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
{% endkatex %}

Plugging the appropriate values for {% katex inline %}a{% endkatex %}, {% katex inline %}b{% endkatex %} and {% katex inline %}c{% endkatex %} into this equation within our Jupyter notebook

```python
a2 = -0.03
b = 1
c = 2

x1_new = (-b + np.sqrt(b**2 - 4*a2*c))/(2*a2)
x2_new = (-b - np.sqrt(b**2 - 4*a2*c))/(2*a2)

print(f"x₁ = {x1_new:.3f} m and x₂ = {x2_new:.3f} m.")
```

gives this output:

```
x₁ = -1.893 m and x₂ = 35.226 m.
```

In other words, the javelin hit the ground after 35.226 m. This result matches our initial guess from the plot of the function. Again, the value for {% katex inline %}x_1{% endkatex %} is negative which tells us that it’s a position _behind_ the person throwing the javelin and is thus a solution that we can disregard as not making physical sense.

### Finding the distance the “German” way

To be able to use the p-q formula, we need to take {% katex inline %}f_2(x){% endkatex %} and consider that we’re finding the {% katex inline %}x{% endkatex %} values when the function is equal to 0. In other words, we need to solve this equation

{% katex %}
-0.03 x^2 + x + 2 = 0
{% endkatex %}

To get things into the right form, we need to divide both sides of the equation by -0.03, which gives

{% katex %}
x^2 - \frac{x}{0.03} - \frac{2}{0.03} = 0
{% endkatex %}

thus we can see that our values for p and q are: {% katex inline %}p = -\frac{1}{0.03}{% endkatex %} and {% katex inline %}q = -\frac{2}{0.03}{% endkatex %}. Remember that the p-q formula is

{% katex %}
x = -\frac{p}{2} \pm \sqrt{\left(\frac{p}{2}\right)^2 - q}
{% endkatex %}

We can now plug in the values for {% katex inline %}p{% endkatex %} and {% katex inline %}q{% endkatex %} to find the two roots of {% katex inline %}f_2(x){% endkatex %} within our Jupyter notebook:

```python
p = -1/0.03
q = -2/0.03

x1 = -p/2 + np.sqrt((p/2)**2 - q)
x2 = -p/2 - np.sqrt((p/2)**2 - q)

print(f"x_1 = {x1:.3f} m and x_2 = {x2:.3f} m")
```

You should see this output:

```
x_1 = 35.226 m and x_2 = -1.893 m
```

which matches the result calculated via the quadratic formula.

### The highest point

The highest point can again be found by taking the derivative of the general form of the function and plugging in the values for {% katex inline %}a{% endkatex %} and {% katex inline %}b{% endkatex %}:

{% katex %}
x = \frac{-b}{2a}
{% endkatex %}

Entering the following code into the Jupyter notebook

```python
a2 = -0.03
b = 1

x_new = -b/(2*a2)

print(f"x at maximum height is {x_new:.3f} m")
```

where I’ve been careful to use a different variable for {% katex inline %}a{% endkatex %} (`a2`) and {% katex inline %}x{% endkatex %} (`x_new`) to avoid clashes with earlier calculations.

Running this code it gives:

```
x at maximum height is 16.667 m
```

which is close to the value we guessed from looking at the plotted curve above. This is also less than the {% katex inline %}\approx 19.05{% endkatex %} m we got from part (a), which matches our intuition from the start of this section. This horizontal distance corresponds to where the javelin is at its highest point, thus we substitute this value for {% katex inline %}x{% endkatex %} in

{% katex %}
f_2(x) = -0.03 x^2 + x + 2
{% endkatex %}

which is

{% katex %}
f_2(16.667) = -0.03 \cdot 16.667^2 + 16.667 + 2
{% endkatex %}

Using Python to do the hard work for us

```
print(f"Maximum height is {-0.03*16.667**2 + 16.667 + 2:.3f} m.")
```

we get

```
Maximum height is 10.333 m.
```

This means that the javelin was thrown a bit lower than the javelin in the initial part of the question. This value matches the maximum of the curve in the plot above as well as our initial intuition of the situation and thus we can be confident that our calculated value is correct.

## What did we learn?

So, after having gone through all this work, what did we learn?

We found out that:

- there’s often more than one way to solve a problem in maths. It’s usually a good idea to follow multiple paths to a solution; a second result will verify an initial answer.
- we can use the inherent symmetry of a problem and a bit of logic to find a solution. Using the symmetry of a quadratic function as well as its roots we were able to find the highest point of the javelin’s path.
- we can use calculus to find the highest (or lowest) points of a function. These points are where the slope (and hence the derivative) of the function are zero. In the example here, this information allowed us to find the highest point of the javelin’s path.
- sometimes the common path to a solution is cultural. In the case here, either you use the quadratic formula or the p-q formula. It doesn’t matter which: both paths lead to the same result.
- it’s not always necessary to use a calculator. Solving things by hand does work and is a useful skill to develop.

That’s it! Happy problem-solving!

1. Found via the `simplest_rational()` method. I.e. `0.02625.simplest_rational()`. [↩](#fnref:sagemath-simplest-rational)