function findiff()
N = 20;
a = -1; b = 1;
A =  1; B = 2;
h = (b-a)/N;
x = linspace(a,b,N+1);
%define rhs
f = func(x(2:N));
rhs = h^2*f'; 
rhs(1) = rhs(1)-A; rhs(N-1) = rhs(N-1)-B; 
%define exact solution
u_exact = uexact(x(2:N),A,B);
%define matrix
v = ones(N-1,1);
D2 = -2*diag(v)+diag(v(1:N-2),1)+diag(v(1:N-2),-1);
%solve by Gauss elimination using matlab \
whos
u = D2\rhs;

plot(x(2:N),u,'ro',x(2:N),u_exact,'k-')

function f = func(x)
f = sin(pi*x);

function u = uexact(x,A,B)
u = -(1/pi^2)*sin(pi*x)+(B-A)*(x+1)/2+A;
