clear all
close all

f=@(x) cos(x)+9*sin(3*x);
uex=@(x) cos(x)+sin(3*x);

a=0;
b=2*pi;
ua=uex(a);
ub=uex(b);

N=50;
hx=(b-a)/N;
x=a:hx:b;
F=f(x)';

M=Lap1D(N+1);
sm=-hx*hx*F; % Second Membre

% Condition de Dirichlet en a
M(1,1)=1;M(1,2)=0;
sm(1)=ua;

% Condition de Dirichlet en b
M(end,end)=1;M(end,end-1)=0;
sm(N+1)=ub;

% Resolution du systeme
U=M\sm;  % U : Solution Differences Finies

figure(1)
plot(x,U,'b',x,uex(x),'r')
xlabel('x')
legend('Sol. D.F.','Sol. Ex.')

figure(2)
plot(x,abs(U-uex(x')))
xlabel('x')
title('Erreur')