# Diffusion Equation with source term

1. Sep 3, 2009

### iva.mn87

I have been asked to solve a diffusion equation with a source term using finite differences method. I need to numerically integrate the following equation either in MATLAB or C++.

The equation is

dT/dt = d2T/dx2 + S(x)

The form of S(x) is some function given by a Gaussian profile.

Could anyone have a solution to the problem!

Thanks!

2. Sep 3, 2009

### pafcu

What exactly is the problem? How far have you gotten?

I've been working on the same problem, and I solved it by using the Crank-Nicolson method. Look it up on e.g. Wikipedia.

A worse, but far simpler method (especially since the source is non-linear) is to use the Forward Euler method:
$$\frac{T(x,t+\Delta t)-T(x,t)}{\Delta t} = \frac{T(x-\Delta x,t)-2T(x,t)+T(x+\Delta x,t)}{(\Delta x)^2} + S(x)$$

Solve for $$T(x,t+\Delta t)$$ and you get
$$T(x,t+\Delta t) = \frac{T(x-\Delta x,t)-2T(x,t)+T(x+\Delta x,t)}{(\Delta x)^2}\Delta t + S(x)\Delta t+T(x,t)$$

So if you know the value of T(x,t) for every x at some time t, you can calculate the value for a future time $$t+\Delta t$$