Finite center difference of poisson equation

5 visualizzazioni (ultimi 30 giorni)
A
A il 12 Mar 2014
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.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by