Solving Poisson's Equation Using 5-Point Stencil In A Rectangular Domain
Solving Poisson's Equation Using 5-Point Stencil:
(*Print["xy: ",xy//MatrixForm];*)
Print["Y: ",Y//MatrixForm];*)
u0 = u;
res = 1;
tol = 10^-6;
iter = 0;
Do[Do[u[[i, j]] = ((u[[i + 1, j]] + u[[i - 1, j]])/h^2 + (u[[i, j + 1]] + u[[i, j - 1]])/k^2 + q[[i, j]])/(2/h^2 + 2/k^2),
{j, 2, n - 1}],
{i, 2, n - 1}]; res = Max[Abs[u0 - u]];
Here contour plot of this solution is attached below:
- By changing the value of dx, you can change the grid size. Warning! If you increase grid size from 21by21 to 81by81 or more it will take very large number of iterations to converge the solution. Here Gauss-Seidel method is applied.
- Mathematica Official website: Visit Mathematica
- Mathematica Documentation Center: Visit Mathematica Documentation Center
Comments
Post a Comment
If you have any doubts, please let me know!