- #1

hunt_mat

Homework Helper

- 1,724

- 16

## Main Question or Discussion Point

So I want to write a short code to solve the diffusion equation and I want to be lazy and use the gradient function for the spacial differences, so for the second order derivative:

[tex]

\frac{f(i+1)-2*f(i)+f(i-1)}{h^{2}}=\textrm{gradient}(\textrm{gradient}(f,h),h)

[/tex]

So the code I wold use is:

[tex]

T=T+dt*D*\textrm{gradient}(\textrm{gradient}(f,h),h)

[/tex]

When I do this, I get erroneous results from my initial condition of a Gaussian for example. values start becoming negative which wrong. I don't know where I am going wrong.

[tex]

\frac{f(i+1)-2*f(i)+f(i-1)}{h^{2}}=\textrm{gradient}(\textrm{gradient}(f,h),h)

[/tex]

So the code I wold use is:

[tex]

T=T+dt*D*\textrm{gradient}(\textrm{gradient}(f,h),h)

[/tex]

When I do this, I get erroneous results from my initial condition of a Gaussian for example. values start becoming negative which wrong. I don't know where I am going wrong.