Setting up diffusion PDE in matlab

In summary, the conversation discussed a numerical simulation of diffusion in MATLAB using Fick's second equation and the Forward time centered scheme for a variable diffusion coefficient. The individual steps for constructing the matrix expression were discussed, but there was a question about expanding it to include boundary conditions. The question was how to expand the matrix expressions to calculate the change in values for all i in the array using the given equation, where N is the size of the array.
  • #1
henxan
46
2
I am going to do a numerical simulation of diffusion in matlab. The diffusion coefficient is concentration dependant, 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
  • #2
What I maybe should have written is, "How do I expand the following matrix expressions to calculate:
[tex]
\Delta u_i^{n+1} = \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}
[/tex]
for all [itex] i \in [2, .. N-1] [/itex] where ##N## is the size of the array ##u \& D##"
 

What is a diffusion PDE?

A diffusion PDE (Partial Differential Equation) is a mathematical equation that describes how a substance, such as heat or mass, diffuses over time and space. It is commonly used in physics, chemistry, and engineering to model various physical processes.

Why is it important to set up a diffusion PDE in Matlab?

Setting up a diffusion PDE in Matlab allows for numerical solutions to be found for complex diffusion problems that cannot be solved analytically. This makes it a powerful tool for modeling and analyzing diffusion processes in various fields of science and engineering.

What are the key components of setting up a diffusion PDE in Matlab?

The key components of setting up a diffusion PDE in Matlab include defining the initial conditions, boundary conditions, and parameters of the diffusion process. This involves identifying the diffusion equation to be solved, specifying the geometry and dimensions of the system, and choosing an appropriate numerical method for solving the PDE.

How do I verify the accuracy of my diffusion PDE solution in Matlab?

One way to verify the accuracy of a diffusion PDE solution in Matlab is to compare it to an analytical solution, if one exists. Alternatively, the solution can be compared to experimental data or validated with other numerical methods. It is also important to check that the solution satisfies the initial and boundary conditions and that the numerical method used is appropriate for the problem at hand.

Can Matlab be used to solve diffusion PDEs in multiple dimensions?

Yes, Matlab has the capability to solve diffusion PDEs in multiple dimensions. However, solving higher dimensional problems can be computationally demanding, so it is important to consider the limitations of the hardware and software being used. Additionally, the choice of numerical method and grid resolution may also affect the accuracy and efficiency of the solution.

Similar threads

  • Advanced Physics Homework Help
Replies
6
Views
2K
  • Advanced Physics Homework Help
Replies
9
Views
827
  • Advanced Physics Homework Help
Replies
1
Views
895
  • Advanced Physics Homework Help
Replies
1
Views
683
  • Advanced Physics Homework Help
Replies
24
Views
682
  • Advanced Physics Homework Help
Replies
3
Views
844
  • Advanced Physics Homework Help
Replies
4
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
775
  • Advanced Physics Homework Help
Replies
1
Views
761
Replies
1
Views
273
Back
Top