import numpy as np class Line: def __init__(self, c0, c1): self.c0, self.c1 = c0, 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 += f'{x:12g} {y:12g}\n' return s class Parabola(Line): def __init__(self,c0,c1,c2): super().__init__(c0,c1) self.c2 = c2 def __call__(self,x): return super().__call__(x) + self.c2*x**2 class SinPlusQuad(Parabola): def __init__(self,a,b,c,A,w): super().__init__(c,b,a) self.A = A self.w = w def __call__(self,x): A, w = self.A, self.w return super().__call__(x) + A*np.sin(w*x) f1 = SinPlusQuad(1,1,1,1,1) print(f1.table(0,5,6)) """ python sin_plus_quadratic.py 0 1 1 3.84147 2 7.9093 3 13.1411 4 20.2432 5 30.0411 """