""" Ex E.3 from "A primer on..." Solve the same ODE as in E.1 and E.2, but this time using the ODESolver class hierarchy. Here we import the solver class from the modele ode_solver.py, so the two files must exist in the same folder. Although we import the ForwardEuler class from the ODESolver hierarchy, the usage of the class is exactly the same as the stand-alone ForwardEuler class in E.2. """ import matplotlib.pyplot as plt import numpy as np from ode_solver import ForwardEuler class SimpleODE: def __init__(self, tau): self.tau = tau def __call__(self, t, u): return self.tau * u problem = SimpleODE(0.1) solver = ForwardEuler(problem) u0 = 0.2 T = 20 N = 4 t, u = solver.solve(u0, (0, T), N) plt.plot(t,u) plt.show()