# Plotting the discrete solution to a PDE

So I went through all the grunt work of solving a PDE in discrete form for a research project. Now I have a Temperature solution as a function of time and space:

$$T_{i}^{n+1}=\left( \dfrac {\lambda _{1}} {\rho_{1}c_{1}}\right)\left( \dfrac {\Delta t} {\Delta r^{2}}\right)\left( 1-\dfrac {\Delta r} {r}\right) T_{i-1}^{n}+\left( 1-2\left( \dfrac {\lambda _{1}} {\rho _{1}c_{1}}\right) \left( \dfrac {\Delta t} {\Delta r^{2}}\right) \right) T_{i}^{n}+\left( \dfrac {\lambda _{1}} {\rho_{1}c_{1}}\right)\left( \dfrac {\Delta t} {\Delta r^{2}}\right)\left( 1+\dfrac {\Delta r} {r}\right) T_{i+1}^{n}+\dfrac {\Delta t} {\rho_{1}c_{1}}\omega_{b1}c_{b}(\left( T_{b}-T_{i}^{n}\right)+\dfrac {\left( P\lambda _{1}\right) } {\omega_{b_{1}}c_{1}})$$

But my problem now is I don't know how to plot this in mathematica. I'm looking to plot this Temperature as a function of time online (for fixed radius).

As you can see, I have delta t and delta r increments and the variable n is my time variable while i is my space variable.

I also have initial conditions for when t = 0 (n = 0). I also have another solution just for i = 0 but I didn't write it out here.

Is this just a matter of creating a recursive function and then using plot? Because I tried that and it isn't working for me.

Any ideas on how to go about plotting this in mathematica would be greatly appreciated. Thanks!

Mathematica Code (with dummy numbers for coefficients):

T[n_, i_] := T[n + 1, i] = 3*T[n, i - 1] + 2*T[n, i] +
3*T[n, i + 1] + 4 ((300 - T[n, i]) + 8)

T[n + 1, 0] = 5*T[n, 0] + 6*(3 + 2 (300 - T[n, 0])) + 10
T[0, i] = 300


Everytime I run this, I get a recursion depth of 256 exceeded.

• Why don't you start by writing that relationship in plain Mathematica syntax? – Dr. belisarius Mar 4 '14 at 5:58
• i've added in the code I've been using. But as I mention, I get a recursion error anytime I try to evaluate T at some n and i. – user402516 Mar 4 '14 at 6:19

I suggest you take a crack at using RecurrenceTable first. But if you want to build up a lot of symbol definitions with recursive calls to T[n,i], you're not far off. The definition for the initial condition should be

T[0, _] := 300


This will evaluate for T[0,1], while your definition will not match i to 1. Check out the Introduction to Patterns. For your boundary equation, try

T[n_, 0] :=  T[n, 0] = 5 T[n-1, 0] + 6 (3 + 2 (300 - T[n-1, 0])) + 10


But (!) this has to be evaluated after the equally generic initial condition. Check out The Ordering of Definitions. The recursion in the interior gives you a RecursionLimit::reclim message because it calls itself with the same arguments. Try instead

T[n_, i_] := T[n, i] = 3 T[n-1, i-1] + 2 T[n-1, i] + 3 T[n-1, i+1] + 4((300 - T[n-1, i]) + 8)


Note that * is unnecessary. Perhaps the plot command you want is

DiscretePlot[T[n,10],{n,0,100}]