3D Diffusion Equation in MATLAB

In summary, the speaker is asking for help with their MATLAB code for solving the 3D Diffusion equation. They suspect that the issue may be related to the use of an explicit scheme for forwarding Fourier coefficients in time. They have now made some progress and are offering a conjecture for potential solutions. They explain the use of discrete and continuous Fourier transform pairs and provide a tip for using fftn() and ifftn() in their code.
  • #1
johnnyTransform
16
2
Hi guys,

I have functioning MATLAB code for my solution of the 3D Diffusion equation (using a 3D Fourier transform and Crank-Nicolsen) that runs just from the command window and automatically plots the results. However, it seems like my solution just decays to zero regardless of what initial condition I use, or boundary conditions I implement. Could I toss this code to somebody so they can run it on their rig and let me know if they can diagnose it? I've been stuck on it for days and I'd much appreciate it.

If you'd like me to post it all in the thread using the code formatting tool, I can do that, but I'll take the suggestion first before completely diluting the post. Thanks guys
 
Physics news on Phys.org
  • #2
Just as a conjecture for those who are curious, I think it may have to do with the fact that I'm forwarding my Fourier coefficients in time using an explicit scheme. However, it's still an open question

EDIT: Sorry, I couldn't find the option to edit my original post. Not trying to bump this up
EDIT 2: Thank you mods, this subforum seems more appropriate for the question. Much appreciated!
 
  • #3
Update: I think I may have figured out my universal decay problem. My solutions now display heat flux, and not just a static decay to zero. I'll explain what I'm thinking might be the trick for people who have similar problems in the future:

Starting with the 3D Diffsuion Eq.: ##u_t=k(u_{xx}+u_{yy}+u_{zz})##, assume the solution has a Fourier expansion (##e^{-ipz},e^{-imy},e^{-inx}##).

Physical space: ##u(x,y,z,t)##. Fourier space: ##c(m,n,p,t)##.

So we have a continuous Fourier transform pair. Once you define your initial condition on a grid, that continuous Fourier transform pair becomes a discrete Fourier transform pair (since your solution becomes discrete once you define it on a grid). In the DFT pair, {n,m,p} is restricted from ##(0,N-1)##, where N is the number of spatial points in your grid.

So, when you're forwarding your Fourier coefficients in time, and you need to loop through your spatial frequencies {n,m,p}, make sure to restrict your loops to positive values, so for example, in MATLAB:
Code:
for n=1:1:N
    for m=1:1:N
        for p=1:1:N

Not:
Code:
for n=-N/2:1:N/2
    for m=-N/2:1:N/2
        for p=-N/2:1:N/2

which would be appropriate if we were still dealing with our continuous Fourier transform pair, which allows for spatial frequencies {n,m,p} over ##(-\infty,\infty)##. The continuous Fourier transform pair is what most people are familiar with, which explains why this would be a natural mistake to make. With this in mind, you can use fftn() and ifftn() to loop back and forth between Fourier space and physical space, while forwarding your Fourier coefficients in time using some type of numerical scheme (for example, Crank-Nicolsen). Hope this is helpful (and correct)!
 

1. What is the 3D diffusion equation and why is it important?

The 3D diffusion equation is a mathematical model used to describe the spread of a substance in three-dimensional space over time. It is important because it can be applied to a wide range of scientific fields, such as physics, chemistry, and biology, to understand diffusion processes and predict the behavior of substances.

2. How can MATLAB be used to solve the 3D diffusion equation?

MATLAB is a powerful computational tool that can be used to solve complex mathematical equations, including the 3D diffusion equation. By inputting the necessary parameters and initial conditions, MATLAB can solve the equation numerically and provide a visual representation of the diffusion process.

3. What are the key parameters needed to solve the 3D diffusion equation in MATLAB?

The key parameters needed to solve the 3D diffusion equation in MATLAB include the diffusion coefficient, the initial concentration of the substance, and the boundary conditions. These parameters determine the behavior of the diffusion process and can be adjusted to simulate different scenarios.

4. Can MATLAB be used to visualize the results of the 3D diffusion equation?

Yes, MATLAB has built-in functions that allow for the visualization of the results of the 3D diffusion equation. This can include creating 3D plots of the concentration distribution over time, as well as animations to show the diffusion process in action.

5. Are there any limitations to using MATLAB for solving the 3D diffusion equation?

While MATLAB is a powerful tool for solving the 3D diffusion equation, it does have some limitations. These include the need for accurate input parameters and the potential for errors in the numerical solution. Additionally, the simulation may not be able to accurately capture all aspects of the diffusion process, such as complex boundary conditions or non-uniform diffusion coefficients.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
Replies
0
Views
461
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Differential Equations
Replies
7
Views
3K
Back
Top