Quadratic word problems (standard form)
1. Fish and water temperature
The number of fish is a function of the water's temperature:
pip install sympy
Which temperatures will result in
import sympy as sp import matplotlib.pyplot as plt import numpy as np def plot(a, b, c, xax, yax): x = sp.Symbol('x') roots = sorted(sp.solveset(a*x**2 + b*x + c)) xaxis = np.arange(roots[0], roots[1], 0.01) yaxis = a*xaxis**2 + b*xaxis + c fig, ax = plt.subplots() ax.plot(xaxis, yaxis) ax.set(xlabel=xax, ylabel=yax) ax.grid() return; plot(-2, 40, -72, 'Temperature', 'Fish') plt.gcf()
There are no fish when
To find the zeros, we need to factor the equation as a product of 2 binomials. First divide by
(defn divide-by-a [[a b c r]] [1 (/ b a) (/ c a) (/ r a)]) (defn div-by-a [s] (map (/ % (first s)) s)) (div-by-a [-2 40 -72 0])
We want to find the positive and negative integer factors of
(defn factors [n] (for [x (into (range (- (Math/abs n)) 0) (range 1 (inc (Math/abs n)))) :when (zero? (rem n x))] [(int x) (int (/ n x))])) (factors 0)
Now find the ones that add up to
(defn zeros [[a b c r]] (map - (first (filter (= b (apply + %)) (factors c))))) (-> [-1 100 0 0] divide-by-a) (zeros [1 -100 0 0])
2. Profit and price of an item
Profit is a function of the price of an item:
plot(-2, 16, -24, 'Price', 'Profit') plt.gcf()
What price results in the maximum profit?
Find the vertex's
(defn average [x y] (/ (+ x y) 2)) (defn vert-x [[a b c r]] (apply average (-> [a b c r] divide-by-a zeros))) (vert-x [-2 16 -24 0])
3. Height of a thrown stone
Alain throws a stone off a bridge into a river below.
The stone's height,
plot(-5, 10, 15, 'Seconds', 'Height') plt.gcf()
What is the height of the stone at the time it is thrown?
That's easy, substitute
4. Height after takeoff
The spaceship's height (in meters),
plot(-2, 20, 48, 'Seconds', 'Height') plt.gcf()
What is the maximum height that the ship will reach?
(vert-x [-2 20 48 0])
The vertex's
Now find
(defn solve [[a b c r] x] (+ (* (* x x) a) (* b x) c)) (solve [-2 20 48 0] 5)
5. Object launched from platform
Its height,
How many seconds after launch will the object land on the ground?
(->> [-5 20 60 0] divide-by-a zeros (apply max))
What is the height of the object at the time of launch?
(solve [-5 20 60 0] 0)
6. Power generated from circuit
The power
What is the maximum power generated by the circuit?
To find the roots, we need to get it into factored form.
Divide by a
:
(div-by-a [-12 120 0])
Divide by the variable
(defn root [[b c]] (- (/ c b))) (defn roots [eq1 eq2] [(root eq1) (root eq2)]) (defn factor-x [[a b c]] [[1 0] [1 (/ b a)]]) (apply roots (factor-x [1 -10 0]))
The vertex's
(defn vertex [[a b c :as eq]] (let [div-a (div-by-a eq) roots (apply roots (factor-x div-a)) x (apply average roots) y (+ (* (* x x) a) (* b x) c)] [x y])) (vertex [-12 120 0])
7. The garden's area
The garden's area
What side width will produce the maximum garden area?
(vertex [-1 100 0])
8. Ball thrown off balcony
The ball's height (in meters above the ground),
How many seconds after being thrown will the ball hit the ground?
(->> [-2 4 16] div-by-a zeros (apply max))
9. Diving altitude
A diver's altitude (in meters relative to sea level),
How many seconds after diving will the diver reach the lowest altitude?
(vertex [1/2 -10 0])