1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Setting up diffusion PDE in matlab

  1. Oct 5, 2014 #1
    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: Oct 5, 2014
  2. jcsd
  3. Oct 5, 2014 #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##"
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Setting up diffusion PDE in matlab
  1. Setting up the KE? (Replies: 3)

Loading...