# 13.3.4 from numpy import *; import matplotlib.pyplot as plt; def euler(f, a, b, x0, n): x = zeros(n+1); x[0] = x0; h = (b-a)/n; t = linspace(a,b, n+1); for k in range(n): x[k+1] = x[k] + h*f(t[k], x[k]); return x; def f(t, x): return x; a = 0; b = 1; n = 10; x0 = 1; t = linspace(a,b,n+1); x_euler = euler(f,a,b,x0,n); plt.plot(t, x_euler, label="Euler"); plt.plot(t, exp(t), label = "Exact"); plt.legend(); plt.show()