function [A]=poistiff(n)
% HA April -97
% Assemble the stiffness matrix of Poisson on unit square
% with "uniform" triangulation.
% Homog. Dirichlet boundary cond.
%
% Ref. E-E-H-Jonsson pp. 359 - 364
%
% n :  nr. of subintervals/axis ( nr. of inner nodes/each axis is   m=n-1)
% Example:
%  pderect([0 1 0 1])  % export: DRAW MENU and BDARY MENU
%  n=3; K1=poistiff(n);
%    Compare to pdetool-functions:  
% [p,e,t]=poimesh(g,n);[K,F,B,ud]=assempde(b,p,e,t,1,0,1);
% [full(K1) full(K)] %  small n            %% comparison
%  K1-K              %  for large n
% 
m=n-1;
N=m^2;
maindiag=4*ones(N,1);
lowd1=[-ones(m-1,m);zeros(1,m)];  % Matrix : [-1 -1 ... -1] (m-1 rows)
lowd1=lowd1(:);                   %          [ 0 0  ..   0] (last row)
                                  % "ravel columnwise" to get the vector
                                  %  [-1 ... -1,0,-1 ... -1,0,...]
upd1=[0;lowd1(1:N-1)];            % Last (N-1) are used
fardiag=-ones(N,1);               % constant => good for both up and low
A=spdiags([fardiag lowd1 maindiag upd1 fardiag],[(-m),-1 0 1,(m)], N,N);

