Kronecker product implementation of finite difference for poisson equation
and thus the forcing function is
. I have the code herein: Accepted Answer
Hi @Aditya,
@Torsten provided file exchange link which is not a bad idea to check. You probably know this that in order to solve the 2D Poisson equation using Kronecker products effectively, it's essential to ensure that both the matrix representation of the differential operator and the right-hand side (RHS) vector correctly reflect the specified boundary conditions. Let me help you understand matrix setup which will help clarify confusion.
Understanding Matrix Setup
1. Matrix (T): The matrix (T) represents a one-dimensional discrete Laplacian operator, which approximates the second derivative. For Dirichlet conditions, you set (T(1,1:2) = [dx^2, 0] at the left edge, which correctly implements a fixed value (Dirichlet). Now, for Neumann conditions, your original setup ( T(end,end-1:end) = [dx, -dx] ) tries to enforce a zero-gradient (Neumann), but it does so incorrectly by using (dx) which scales with grid spacing rather than enforcing a constant gradient.
2. Boundary Condition Vector ( b ): The right-hand side vector (b) must reflect your boundary conditions accurately. When you implemented (b(:,end) = -16*y'.^2; )and (b(end,:) = -16*x.^2; ), these terms were not scaled correctly for Neumann conditions since they need to reflect flux rather than values at boundaries. You can double check this.
Here is my modified approach:
T(end,end-1:end) = [1 -1]; % Correct for Neumann condition b(:,end) = -16*y'.^2/dx; % Correct scaling for right boundary b(end,:) = -16*x.^2/dx; % Correct scaling for top boundary
This change will ensure that:
*The Neumann condition is enforced correctly by setting it up as a finite difference approximation for derivatives (using differences rather than scaled values).
*The RHS incorporates (dx) scaling to reflect that these are derivatives (fluxes), which is appropriate for Neumann boundaries.
Here are some additional points to help further
Kronecker Product Usage: Your use of `L = kron(T,I) + kron(I,T); is appropriate as it constructs a 2D Laplacian from a 1D version effectively. Just ensure that both components correctly reflect your boundary conditions.
Numerical Stability: Ensure that your grid size (N)is sufficiently large to minimize numerical errors due to discretization.
Visualization: After solving, comparing your numerical solution against an analytical solution (as you did with u_an) is an excellent practice for validating your implementation.
Further Testing: It might be beneficial to test various grid sizes and compare results to confirm stability across different configurations.
In nutshell, your initial confusion stemmed from misapplying Neumann boundary conditions in both matrix construction and RHS definition. By correcting these elements, you aligned your numerical approach with theoretical expectations, yielding accurate results.
Hope this helps.
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!