You are on page 1of 15

Example y=1

y = -1
Find Cij ?
Let us refine
the mesh…

log (Error L2)

log (1/h)
MATLAB
function convergence()

h = [1 2 4 8 16 32 64]
for (i=1:length(h))
error(i) = errorL2(h(i))
end
loglog(h,error);
X = XY(:,1);
Y = XY(:,2);

n = size(XY,1);
A = sparse(n,n);
B = zeros(n,1);

for(ielem=1:size(appart,1))
iloc = appart(ielem,:);
dirichlet = ((bnd(iloc,1)==1)|(bnd(iloc,2)==1));

[Aloc Bloc] = mat_loc(X(iloc),Y(iloc));


[Aloc Bloc] = mat_constr(Aloc,Bloc,dirichlet);

A(iloc,iloc) = A(iloc,iloc) + Aloc;


B(iloc,1) = B(iloc,1) + Bloc;
end

U = A\B;

Assembling and
solving the
linear system
Local matrices are exactly
% local matrix computed
function [A,B] = mat_loc(X,Y)

dphidxi = [-1 -1; 1 0; 0 1 ];


Je = det( [X(2)-X(1) X(3)-X(1); Y(2)-Y(1) Y(3)-Y(1)] );
dxidx = [Y(3)-Y(1) X(1)-X(3); Y(1)-Y(2) X(2)-X(1)] / Je;
dphidx = dphidxi * dxidx;

A = (Je / 2) * (dphidx * dphidx');


B = - (Je /6 ) * ones(3,1);

% imposing essential boundary condition

function [A,B] = mat_constr(A,B,iloc)

A(:,iloc)=0;
A(iloc,:)=0;
A(iloc,iloc) = diag(ones(size(B(iloc))));
B(iloc) = 0;

% analytical solution

function u = solution(x,y)

u = zeros(size(x));
for(i=101:-2:1)
for(j=101:-2:1)
u = u - sin((i*pi/2)*x).*sin((j*pi/2)*y) / ((i*i+j*j)*i*j);
end
end
u = (64/(pi^4))*u;

You might also like