Solving Poisson Equation with FFT in MATLAB

  • MATLAB
  • Thread starter rustpanjguh
  • Start date
  • Tags
    Fft Poisson
In summary, the conversation discusses using a numerical solver to solve the Poisson equation with periodic and Neumann boundary conditions. The speaker asks for help in finding non-periodic, non-smooth functions to test the code and inquires about the expected results. The expert suggests using functions such as a Gaussian or a step function and explains how to implement them in Matlab. The expected results vary depending on the function and the accuracy of the code.
  • #1
rustpanjguh
1
0
Hi,

As part of my homework, I wrote a MatLab code to solve a Poisson equation
Uxx +Uyy = F(x,y)

with periodic boundary condition in the Y direction and Neumann boundary condition in the X direction. I used the finite difference method in the X direction and FFT in the Y direction to numerically solve for Uxx and Uyy. Now the teacher is asking to use our numerical solver and test it for interesting functions.

My code solves the equations with above conditions and with smooth U with order two accuracy, and now the teacher wants us to run our code for interesting cases, like non-periodic functions or non-smooth functions.
Here are my questions:

1. I need help coming up with a periodic (in y) non-smooth function so I can test my code. Can someone help me find such functions? (MatLab implementation of function would be great)

2. When I find such function and run my code using it, then what should I expect? Should I expect that a 1st order approximation, or total explosion of solution?

3. As I mentioned For a non periodic function I got a 1st order error rate. Is that what I should expect?
 
Physics news on Phys.org
  • #2


Hi there,

It's great that you have successfully implemented a numerical solver for the Poisson equation with periodic and Neumann boundary conditions. To test your code for interesting cases, you can try using non-periodic functions such as a Gaussian or a step function. These functions have different smoothness and can provide a good test for your code.

To implement a Gaussian function in Matlab, you can use the "normpdf" function which generates a normal probability distribution. You can then use this function to create a 2D Gaussian function with different means and standard deviations. For example, the following code creates a 2D Gaussian with a mean of 0 and a standard deviation of 1:

x = linspace(-5,5,100);
y = linspace(-5,5,100);
[X,Y] = meshgrid(x,y);
Z = normpdf(X,0,1).*normpdf(Y,0,1);
surf(X,Y,Z)

You can also try using a step function, which can be implemented in Matlab using the "heaviside" function. This will create a step function with different step locations and heights. For example, the following code creates a step function with a step at x=0 and a height of 1:

x = linspace(-5,5,100);
y = zeros(size(x));
y(x>=0) = 1;
plot(x,y)

When running your code with these functions, you should expect to see a solution that is not smooth and has discontinuities. Depending on the function and the accuracy of your code, you may see a first-order or even a second-order error rate. It is important to also check the convergence of your solution as you refine your grid size to ensure that your code is producing accurate results.

I hope this helps and good luck with your code testing! Let me know if you have any further questions.
 

Related to Solving Poisson Equation with FFT in MATLAB

What is the Poisson equation?

The Poisson equation is a partial differential equation that describes the relationship between a function and its sources. It is commonly used in physics and engineering to model the behavior of electric and gravitational fields.

Why is the FFT method used to solve the Poisson equation in MATLAB?

The FFT (Fast Fourier Transform) method is used because it allows for efficient and accurate numerical solutions to the Poisson equation. It takes advantage of the fact that the equation is based on the Fourier transform, which can be computed quickly using the FFT algorithm.

How does the FFT method work for solving the Poisson equation in MATLAB?

The FFT method works by converting the Poisson equation into its Fourier domain equivalent, which can then be solved using the FFT algorithm. This involves taking the 2D or 3D grid of data points and transforming it into a series of sine and cosine coefficients, which can then be manipulated to obtain the solution.

What are the limitations of using the FFT method to solve the Poisson equation in MATLAB?

One limitation is that the FFT method is only applicable to certain types of boundary conditions, such as periodic or Dirichlet boundary conditions. Additionally, the accuracy of the solution can be affected by the choice of grid size and the smoothness of the function being solved.

Are there alternative methods to solving the Poisson equation in MATLAB?

Yes, there are alternative methods such as finite difference and finite element methods that can also be used to solve the Poisson equation in MATLAB. These methods may be more suitable for certain types of boundary conditions or for problems with complex geometries.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
13K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
885
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
Back
Top