Bobbi Towers / May 14 2019

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 fish?

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 to get by itself:

(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])
List(4) (1, -20, 36, 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)
List(0) ()

Now find the ones that add up to and solve for by taking their negatives:

(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])
List(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 -coordinate by taking the average of the two zeros:

(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])
4

3. Height of a thrown stone

Alain throws a stone off a bridge into a river below.

The stone's height, seconds after Alain threw it, is modeled by:

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 for to get .

4. Height after takeoff

The spaceship's height (in meters), seconds after takeoff, is modeled by:

plot(-2, 20, 48, 'Seconds', 'Height')
plt.gcf()

What is the maximum height that the ship will reach?

(vert-x [-2 20 48 0])
5

The vertex's -coordinate is .

Now find :

(defn solve [[a b c r] x]
  (+ (* (* x x) a)
     (* b x)
     c))

(solve [-2 20 48 0] 5)
98

5. Object launched from platform

Its height, seconds after the launch, is modeled by:

How many seconds after launch will the object land on the ground?

(->> [-5 20 60 0]
  divide-by-a
  zeros
  (apply max))
6

What is the height of the object at the time of launch?

(solve [-5 20 60 0] 0)
60

6. Power generated from circuit

The power generated by an electrical circuit (in watts) as a function of its current (in amperes) is modeled by:

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])
List(3) (1, -10, 0)

Divide by the variable and take the root of each term:

(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]))
Vector(2) [0, 10]

The vertex's coordinate is the average of the 2 roots; which we will then plug into the equation for the coordinate:

(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])
Vector(2) [5, 300]

7. The garden's area

The garden's area is a function of the garden's width :

What side width will produce the maximum garden area?

(vertex [-1 100 0])
Vector(2) [50, 2500]

8. Ball thrown off balcony

The ball's height (in meters above the ground), seconds after being thrown, is modeled by:

How many seconds after being thrown will the ball hit the ground?

(->> [-2 4 16]
  div-by-a
  zeros
  (apply max))
4

9. Diving altitude

A diver's altitude (in meters relative to sea level), seconds after diving, is modeled by:

How many seconds after diving will the diver reach the lowest altitude?

(vertex [1/2 -10 0])
Vector(2) [#n"10", #n"-50"]