2
$\begingroup$

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.

Edit:

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

Clear["Global`*"];
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}];
ListLinePlot[TFinal[1]]

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.

$\endgroup$
  • $\begingroup$ trott's books are very good:Trott $\endgroup$ – Spawn1701D Apr 10 '13 at 4:35
  • $\begingroup$ 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. $\endgroup$ – random dude Apr 10 '13 at 16:21
2
$\begingroup$

This book should be helpful, I think it's what you're looking for.

Numerical and Analytical Methods for Scientists and Engineers, Using Mathematica

Also The Mathematica GuideBook for Numerics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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