Finite center difference of poisson equation
6 ビュー (過去 30 日間)
古いコメントを表示
Hello!
This is my first time attempting to write a finite difference method in matlab, and I am a bit confused about how to construct my grid, and assign initial values before solving the poisson equation, d^2x/dx^2 + d^2y/dy^2=-2
I want to have a square domain grid from [xmin=0,xmax=3], [ymin=0,ymin=3], with a separation distance h=1.
I have tried using this:
[x,y]= ndgrid(0:1:3,0:1:3)% [x,y] = ndgrid(xmin:hx:xmax,ymin:hy:ymax)
to create the grid
and ideally, I need to have the problem written in the form Ax=b, where A is a matrix which defines the coefficients of u(i+1,j), u(i-1,j), u(i, j+1), u(i,j-1)
The initial conditions are ui=(1,1,1,1);
The boundary conditions are u(0,y)=0, u(x,3)=0, u(x,0)=1, u(3,y)=2;
Using the forward centered difference equations, I want to populate the matrix A by:
for i=2:n-1 for j=2:m-1 A(i,j)= 4*u(i,j) - u(i-1,j) - u(i+1,j) - u(i,j-1) - u(i,j+1); end end
but I am not really sure how to construct this finite difference method, or how to obtain pliable expressions for the matrix A, and vectors x and b in the Ax=b form. Any guidance or advice is greatly appreciated.
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!