Computational Physics, Physics, Heat Equation, Python, Math.
to PEP8: # https://www.python.org/dev/peps/pep-0008/#id19 f = (np.exp(-4*np.pi**2*alpha*t) * np.sin(2*np.pi*x) + 2.0*(1-np.exp(-np.pi**2*alpha*t)) * np.sin(np.pi*x) / (np.pi**2*alpha)) return f And now we perform the time stepping: T = np.empty((nt+1, nx)) T[0] = T0.copy() for i in range(nt):