function findiff()
% spatial discretization
figure
N = 100;
a = -1; b = 1;
h = (b-a)/N;
x = linspace(a,b,N+1);
% temporal discretization
T = 1; dt = .01;
K = T/dt;
%define IC - BC
f = func(x(2:N));
A =  0; B = 0;
u(:,1) = f';  
%define matrix
r = h^2/dt;
v = ones(N-1,1);
D2s = spdiags([v -(2+r)*v v],-1:1,N-1,N-1);
[L,U] = lu(D2s);
%solve by Gauss elimination using matlab \
%whos
v = [A;u(:,1);B];
plot(x,v);
hold on
for k = 2:K+1
    rhs = -r*u(:,k-1);
    rhs(1)   = rhs(1)   - A;
    rhs(N-1) = rhs(N-1) - B;
    y = L\rhs;
    u(:,k)  = U\y;
    v = [A;u(:,k);B];
    plot(x,v,'r-')
    hold on
    axis([-1 1 -1 1])
    pause(1)
end
%
%y = L\rhs;
%u = U\y;


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

