""" Exercise 7.11 from "A primer on... Modify the class from ex 7.1 with secial methods, to make the gi ven use examples work. The example below is a slightly improved version of the class, which includes the parameter values in the output from __str__, not jus "a" and "w". """ import numpy as np 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)" f = F(a=1.0, w=0.1) print(f(x = np.pi)) #output: 0.013353835137 f.a = 2 print(f(np.pi)) #output: 0.00057707154012 print(f) #output: exp(-2*x)*sin(0.1*x) """ Terminal> python F2.py 0.01335383513703555 0.0005770715401197441 exp(2*x)*sin(0.1*x) """