Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm afraid this is probably not going to be a "good" question, but I'd like to use Mathematica to learn about basic numerical schemes for solving pdes. For example, I'd like to compute the solution of a 2D heat equation initial value problem using finite differences and Euler timestepping, and then look at how big errors are or stability (not interested in using NDSolve directly).

My question is, are there any resources that already do this the "right" way? I'm just getting acquainted with Mathematica and don't know the language well, but I do know I want to use packed arrays and avoid loops. There's lots of language-agnostic references for the numerical methods themselves, but I can't find good clean examples of Mathematica implementations of these methods.


One of the books recommended in the answers suggest doing stuff like (1d heat equation IVP):

gridX = 10; (* num interior points *)
dx = 1./gridX;
dt = .005; (*cfl: dt/dx^2 <= .5 *)

T[i_, j_] := T[i, j] = T[i, j - 1] + 
                  (dt/dx^2) (T[i + 1, j - 1] - 2 T[i, j - 1] + T[i - 1, j - 1]);

T[i_, 0] := 1. (* initial value *)

T[0,         j_] := 0.; (* boundaries *)
T[gridX + 1, j_] := 0.; 

TFinal[t_] := Table[T[i, IntegerPart[t/ dt]], {i, 1, gridX}];

But I suspect that it's not the best way, because as soon as I crank up the grid size and shrink down the time step, I get a recursion limit error. The code above is storing the solution at all time steps, which I definitely don't want. I'm sure there are clean, non-recursive sample implementations of this method out there, just can't seem to find.

share|improve this question
trott's books are very good:Trott –  Spawn1701D Apr 10 '13 at 4:35
Your question asked for resources not books that will hold your hands. Now you should probably ask a different question instead of editing the same question that asks for resources to solicit answers to a different question. –  RunnyKine Apr 10 '13 at 15:26
a book is not a resource? in any case, i'm just interested in seeing some code, don't care if it's in a book, a website, or a stone tablet. what i'm definitely not interested in are comments like yours. just move along. –  random dude Apr 10 '13 at 16:21
add comment

1 Answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.