""" From "A SURVEY OF COMPUTATIONAL PHYSICS", Python eBook Version by RH Landau, MJ Paez, and CC Bordeianu Copyright Princeton University Press, Princeton, 2012; Book Copyright R Landau, Oregon State Unv, MJ Paez, Univ Antioquia, C Bordeianu, Univ Bucharest, 2012. Support by National Science Foundation , Oregon State Univ, Microsoft Corp""" # OOPBeats.py: OOP superposition of two sine waves from pylab import * # graphics and math classes class OOPbeats: def __init__(self, Ampl, freq1, freq2): # class constructor self.A = Ampl # Amplitude self.k1 = freq1 # frequencies self.k2 = freq2 def sumwaves(self): x = arange(0., +5.0, 0.01) # min, max, step y = self.A*sin(self.k1*x) + self.A*sin(self.k2*x) plot(x,y) show() beats=OOPbeats(1.0,30.0,33.0) # instance of class beats.sumwaves()