function fish_test % FISH TEST % % This is an example of how to use Tim's fast Poisson solver (P2D.m) % to solve Poisson's equation in Matlab. You will have to use Matlab's % reshape command. % % My codes require that h be a power of 1/2. In this example h=1/64. % % You will need these codes, which I have posted on the course web page. % % P2D.m (solver) % lapmf.m (matrix-free negative Laplacian) % % Both of these codes expect you to reshape to a linear array and % then you have to undo it when the solver returns. % % The first step is to set up the grid. I will use N=63 interior grid % points in each direction. Note that the last command makes x a column % vector. % n=63; h=1/(n+1); x=1:n; x=x'*h; % % Now I will invent a solution u(x,y) = sin(pi x)*sin(pi*y)*rand(n,n). % sinx=sin(pi*x); u=sinx*sinx'; ru=rand(n,n); u=u.*ru; % % So the right side is f(x,y) = -u_xx -u_yy % % It's now time to do the reshape. Turn u from a 2D grid function into % a linear array u1. % u1=reshape(u,n*n,1); % % Now apply the 2D Laplacian in matrix-free form. % rhs=lapmf(u1); % % Feed it to the solver % sol=P2D(rhs); % % Use reshape again to map to the physical grid. % uout=reshape(sol,n,n); % % Check the results. % max(max(uout-u))