To apply a function to a vector, take advantage of
Listable functions when possible:
Use
Table and
Part to access elements of
v as might be done in a lower-level language:
The results are the same up to numerical roundoff:
Use efficient sparse arithmetic to numerically solve the heat equation

:
Matrix for a second-order approximation to the second derivative on the grid

:
Incorporate Dirichlet boundary conditions to form the Jacobian J:
The sparse identity matrix:
Form sparse matrix

for

using the listability of arithmetic:
Step initial condition on spatial grid
x using the listability of
UnitStep:
Get the solution at

,

using the backward Euler method: