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).
- Write a class whose constructor takes two arguments
(c0, c1)
and whose objects are either,- in Python, callable that return the function value $f(x)$ at the specified $x$ value when called or,
- have a method named
eval(x)
that computes $f(x)$ at the specified $x$ value.
- 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 superclassLine()
you have implemented above.
Write a subclassParabola
that inherits its(c0, c1)
coefficients from the superclassLine
, but its constructor also adds a third coefficientc3
which makes it a parabola.
This class must be either,- in Python, callable that returns the function value $f(x)$ at the specified $x$ value when called or,
- have a method named
eval(x)
that overrides the parent methodeval()
inherited from the superclassLine()
and computes $f(x)$ at the specified $x$ value.
- 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))