A lazy numerical solution to the diffusion equation

In summary, you are trying to solve the diffusion equation with arbitrary initial conditions and boundary conditions and are getting erroneous results.
  • #1
hunt_mat
Homework Helper
1,782
32
So I want to write a short code to solve the diffusion equation and I want to be lazy and use the gradient function for the spatial differences, so for the second order derivative:
[tex]
\frac{f(i+1)-2*f(i)+f(i-1)}{h^{2}}=\textrm{gradient}(\textrm{gradient}(f,h),h)
[/tex]

So the code I wold use is:

[tex]
T=T+dt*D*\textrm{gradient}(\textrm{gradient}(f,h),h)
[/tex]

When I do this, I get erroneous results from my initial condition of a Gaussian for example. values start becoming negative which wrong. I don't know where I am going wrong.
 
Physics news on Phys.org
  • #2
I think you will need to be more specific about what you are doing and what result you are trying to obtain relative to what you get. Also, posting your code would be helpful.
 
  • #3
My goal is solving the diffusion equation with arbitrary initial conditions and arbitrary boundary conditions.

One problem I noted was I wasn't using the CFL condition on time. Once I did that it worked fine. I have yet to check it works with the formulation above yet.
 
  • #4
Not satisfying the CFL condition of course would make your solution unstable. I once taught this to students and made a point out of not telling them about it as I was telling them how to discretise the heat equation. Then I purposely set ##\Delta t## just above the limit for stability to have the resulting animation start out as expected but break down after about ten seconds. That brought down some laughs as I said "... and we see that the solution behaves perfectly as expected ..." at the same time as it started to diverge and a cautionary tale to make sure students would take care to check their stability conditions and not blindly apply numerical recipes.
 
  • #5
Schoolboy error. It's been a long long time since I had to numerically solve a PDE...
 

1. What is the diffusion equation?

The diffusion equation is a mathematical model that describes the process of how particles spread out or diffuse through a medium over time. It is commonly used in fields such as physics, chemistry, and biology to study a variety of phenomena, including heat transfer, chemical reactions, and population dynamics.

2. What is a lazy numerical solution?

A lazy numerical solution refers to a simplified or approximate method of solving the diffusion equation. It involves using pre-computed data or assumptions to quickly calculate the solution, rather than performing the more rigorous and time-consuming calculations required for an exact solution.

3. How does a lazy numerical solution differ from other methods?

A lazy numerical solution differs from other methods in that it sacrifices accuracy for efficiency. It may not provide an exact solution, but it can still offer valuable insights and predictions, especially when dealing with complex or large-scale systems.

4. What are the advantages of a lazy numerical solution?

One advantage of a lazy numerical solution is that it is often much faster and less resource-intensive than other methods, making it ideal for large and complex systems. It also allows for the incorporation of real-world data and can provide a more intuitive understanding of the diffusion process.

5. Are there any limitations to using a lazy numerical solution?

Yes, there are some limitations to using a lazy numerical solution. It may not always provide an accurate representation of the system, particularly in cases where the diffusion is highly non-linear or when there are significant variations in the diffusion coefficient. Additionally, it may not be suitable for studying small-scale or highly detailed processes.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • Advanced Physics Homework Help
2
Replies
36
Views
2K
Replies
13
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
8
Views
470
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Replies
0
Views
459
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
Back
Top