#### Solution to exercise 9.3 in the book import numpy as np import matplotlib.pyplot as plt # Class Line is from section 9.1.1 in the book class Line: def __init__(self, c0, c1): self.c0 = c0 self.c1 = c1 def __call__(self, x): return self.c0 + self.c1*x def table(self, L, R, n): """Return a table with n points for L <= x <= R.""" s = '' for x in np.linspace(L, R, n): y = self(x) s += '%12g %12g\n' % (x, y) return s # Class Parabola is from section 9.1.3 in the book class Parabola(Line): def __init__(self, c0, c1, c2): Line.__init__(self, c0, c1) self.c2 = c2 def __call__(self, x): return self.c0+self.c1*x+self.c2*x**2 # This is the class we are asked to program in ex. 9.3 class SinPlusQuadratic(Parabola): def __init__(self, A, w, a, b, c): Parabola.__init__(self, c, b, a) self.A = A self.w = w def __call__(self, x): return self.A * np.sin(self.w * x) + Parabola.__call__(self, x) # Example usage: # Create an instance of the class f = SinPlusQuadratic(1.0, 10.0, 1.0, 0.5, 0.0) # Compute and plot the function x = np.linspace(-5, 5, 1000) plt.plot(x, f(x)) plt.show()