""" Ex. 5.11 from "A primer on..." Modify the class from ex 6.1 with special methods __call__ and __str__. """ import numpy as np from math import pi class F: def __init__(self, a, w): self.a = a self.w = w def __call__(self, x): return np.exp(-self.a*x) * np.sin(self.w*x) def __str__(self): return f'exp(-{self.a}*x) * sin({self.w}*x)' #usage: f = F(a=1.0, w=0.1) print(f(x=pi)) print(f) """ Terminal> python F2.py 0.01335383513703555 exp(-1.0*x) * sin(0.1*x) """