Diffusion Equation with source term

Click For Summary
The discussion focuses on solving a diffusion equation with a source term using finite difference methods in MATLAB or C++. The equation presented is dT/dt = d2T/dx2 + S(x), with S(x) defined by a Gaussian profile. One participant suggests using the Crank-Nicolson method for a more accurate solution, while another recommends the simpler Forward Euler method, providing a formula for calculating future temperature values. The Forward Euler method is noted as less accurate, especially due to the non-linear source term. The conversation emphasizes the need for numerical integration techniques to address the problem effectively.
iva.mn87
Messages
1
Reaction score
0
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!
 
Physics news on Phys.org
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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 2 ·
Replies
2
Views
2K