A numerical method for the solution of the diffusion equation in multilayered systems