How to Construct a Matrix for Diffusion PDE in MATLAB?

Click For Summary
SUMMARY

This discussion focuses on constructing a matrix for simulating diffusion in MATLAB using Fick's second equation. The user employs a Forward Time Centered Scheme for a variable diffusion coefficient, D(x), which is calculated using array operations. The matrix representation of the diffusion process is established, but the user seeks guidance on expanding this matrix expression to calculate the change in concentration, Δu_i^{n+1}, for all interior points while incorporating boundary conditions.

PREREQUISITES
  • Understanding of Fick's second law of diffusion
  • Proficiency in MATLAB programming
  • Knowledge of numerical methods for partial differential equations
  • Familiarity with matrix operations and boundary conditions in numerical simulations
NEXT STEPS
  • Research how to implement boundary conditions in MATLAB for PDEs
  • Learn about MATLAB's built-in functions for matrix manipulation
  • Explore advanced numerical methods for solving diffusion equations
  • Study the stability and convergence criteria for numerical schemes in PDEs
USEFUL FOR

Researchers, engineers, and students involved in computational physics, particularly those focusing on numerical simulations of diffusion processes using MATLAB.

henxan
Messages
46
Reaction score
2
I am going to do a numerical simulation of diffusion in matlab. The diffusion coefficient is concentration dependent, and i use an array operation to calculate D(x), so it is known.

Based on Fick's second equation:

$$
\frac{\partial C}{\partial t} = \frac{\partial}{\partial x} D \frac{\partial C}{\partial x}
$$

I am going to use the Forward time centered scheme for a variable D:

$$
u_i^{n+1} = u_i^{n} + \frac{\Delta t}{2\Delta x^2}\left( \left( D_{i+1}^n + D_{i}^n \right) \left(u_{i+1}^n -u_i^n \right) - \left( D_{i}^n + D_{i-1}^n \right) \left(u_{i}^n -u_{i-1}^n \right)\right)
$$

How can i construct a matrix which I can put into matlab? I can do the following with the rightmost expression:

$$
\left( \left( D_{i+1}^n + D_{i}^n \right) \left(u_{i+1}^n -u_i^n \right) - \left( D_{i}^n + D_{i-1}^n \right) \left(u_{i}^n -u_{i-1}^n \right)\right) = \begin{pmatrix} D_{i-1}^{n} & D_{i}^{n} & D_{i+1}^{n} \end{pmatrix} \begin{pmatrix} 1 & -1 & 0\\ 1 & -2 & 1\\ 0 & -1 & 1 \end{pmatrix} \begin{pmatrix} u_{i-1}^{n} \\ u_{i}^{n} \\ u_{i+1}^{n} \end{pmatrix}
$$

But how can I apply this to the entire row n+1 and include boundary conditions?
 
Last edited:
Physics news on Phys.org
What I maybe should have written is, "How do I expand the following matrix expressions to calculate:
<br /> \Delta u_i^{n+1} = \begin{pmatrix} D_{i-1}^{n} &amp; D_{i}^{n} &amp; D_{i+1}^{n} \end{pmatrix} \begin{pmatrix} 1 &amp; -1 &amp; 0\\ 1 &amp; -2 &amp; 1\\ 0 &amp; -1 &amp; 1 \end{pmatrix} \begin{pmatrix} u_{i-1}^{n} \\ u_{i}^{n} \\ u_{i+1}^{n} \end{pmatrix}<br />
for all i \in [2, .. N-1] where ##N## is the size of the array ##u \& D##"
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
Replies
4
Views
1K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
4
Views
4K
  • · Replies 21 ·
Replies
21
Views
1K
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
1
Views
2K