I got a matlab code which basically solves an equation of 2D distribution of heat on (x,y) plate. The differential equation for this is
$$ \rho (x,y)C(x,y) \frac{d T}{d t} - \nabla (k(x,y) \nabla T)=f(x,y) $$
In matlab I solve it by finite difference method like this
$$ { \rho }_{i,j,l} C_{i,j,l} \frac{T_{i,j,l}-T_{i,j,l-1}}{ \Delta t} - \frac{1}{ {\Delta x}^{2} } (k_{i,j,l}(T_{i+1,j,l}-T_{i,j,l})-k_{i-1,j,l}(T_{i,j,l}-T_{i-1,j,l})) - \frac{1}{ {\Delta y}^{2} } (k_{i,j,l}(T_{i,j+1,l}-T_{i,j,l})-k_{i,j-1,l}(T_{i,j,l}-T_{i,j-1,l}))=f_{i,j,l} $$
But in my case I'd like to solve it for a hot cylinder with radius R and hight Z and to demonstrate the dynamics of cooling. As long as this problem has symmetry, the equation can be transformed to this
$$ r\rho (r,z)C(r,z) \frac{d T}{d t} - \frac{d }{d r} (k(r,z) r \frac{d T}{d r}) - \frac{d }{d z}( k(r,z)\frac{d T}{d z})=f(r,z) $$
I decided to change the finite difference model like this
$$ r{ \rho }_{i,j,l} C_{i,j,l} \frac{T_{i,j,l}-T_{i,j,l-1}}{ \Delta t} - \frac{1}{ {\Delta r}^{2} } (k_{i,j,l}(r_{i+\frac{1}{2}}T_{i+1,j,l}-(r_{i+\frac{1}{2}}+r_{i-\frac{1}{2}})T_{i,j,l})-k_{i-1,j,l}((r_{i+\frac{1}{2}}+r_{i-\frac{1}{2}})T_{i,j,l}-r_{i-\frac{1}{2}}T_{i-1,j,l})) - \frac{1}{ {\Delta z}^{2} } (k_{i,j,l}(T_{i,j+1,l}-T_{i,j,l})-k_{i,j-1,l}(T_{i,j,l}-T_{i,j-1,l}))=f_{i,j,l} $$
because in one book I've found such relation
$$ \frac{d }{d r} (r \frac{d T}{d r}) = \frac {1}{h^2} (r_{i+\frac{1}{2}}T^{n+1}_{i+1} -(r_{i+\frac{1}{2}}+r_{i-\frac{1}{2}})T^{n+1}_{i} + r_{i-\frac{1}{2}}T^{n+1}_{i-1}) $$ where $ r_{i-\frac{1}{2}}=\frac {r_{i-1}+r_i}{2}$ and $r_{i+\frac{1}{2}}=\frac{r_i+r_{i+1}}{2}$
The questions are:
Is this equation for cylindrical coordinates correct?
It seems to me that it impossible so simply transform a 2D cartesian problem to a reduced 3d cylindrical one?
Am I missing something and if no, how to visualize (r,z) result correctly in matlab? Just can't imagine.
The formula you found in the book is a more accurate finite difference approximation than the formula you were using. But, if you made that improvement with respect to the r's, the improvement would have been even better if you applied the same approach to the k's (or to the combination of kr).