function ueb5
%
% Matlab-File for the Solution of the Lab Exercise of the 
% 5. Exercise Sheet of the Lecture
% "Numerical Analysis and Simulation II: 
%  Partial Differential Equations (PDEs)"
% M. Ehrhardt, SS 2012
%
% -(u_xx+u_yy) = 3*x^2, -1<x<1, -1<y<1
%
% u(1,y) = .25*sin((y+1)/2*pi), -1<y<1
%
% u(x,y)=0, on the remaining part of the boundary
%

clear
close all
                                                   
dx = 1/8; % Schrittweite in x-Richtung
dy = dx;  % Schrittweite in y-Richtung
Nx = 1/dx+1; % Anzahl Gitterpunkte in x 
Ny = Nx; % Anzahl Gitterpunkte in y

[x,y] = meshgrid(-1:dx:1,-1:dy:1);
eins = ones(Nx-2,1);
T = spdiags([-eins 4*eins -eins],-1:1,Nx-2,Nx-2);
Eins = speye(Nx-2);

X=spdiags([-eins eins],[-1,1],Nx-2,Nx-2);
M=(kron(Eins,T)+kron(X,Eins))/dx^2;
f=ones((Nx-2)^2,1);

loesung=M\f;
loesung = reshape(loesung,Nx-2,Nx-2);

u=zeros(Nx,Ny);
u(2:Nx-1,2:Ny-1)=loesung;
mesh(x,y,u);











