Problem

Recall the equation for a line is given by $f(x) = c_0 + c_1 x$ where $c_0$ and $c_1$ are the constants of the equation (intercept and slope, respectively).

  1. Write a class whose constructor takes two arguments (c0, c1) and whose objects are either,
    1. in Python, callable that return the function value $f(x)$ at the specified $x$ value when called or,
    2. have a method named eval(x) that computes $f(x)$ at the specified $x$ value.
  2. Recall the equation for a parabola is given by $f(x) = c_0 + c_1 x + c_2 x^2$.
    Therefore, parabola can be considered as a subclass of the superclass Line() you have implemented above.
    Write a subclass Parabola that inherits its (c0, c1) coefficients from the superclass Line, but its constructor also adds a third coefficient c3 which makes it a parabola.
    This class must be either,
    1. in Python, callable that returns the function value $f(x)$ at the specified $x$ value when called or,
    2. have a method named eval(x) that overrides the parent method eval() inherited from the superclass Line() and computes $f(x)$ at the specified $x$ value.
  3. Now compute the result for the following coefficients and x value (code is in Python syntax).
    parabola = Parabola(1, -2, 2)
    print(parabola(x = 2.5))
    

Comments