%n=5
fprintf('We have the number of steps to n=%i\n',n)
x=linspace(0,10,n);
h=(10-0)/(n-1);
bcleft=1;
bcright=0;

ID=sparse(2:n-1,2:n-1,1,n,n);
UP=sparse(2:n-1,3:n,1,n,n);
DN=sparse(2:n-1,1:n-2,1,n,n);
secderv=(UP-2*ID+DN)/h^2;
derv=(UP-DN)/(2*h);

% variable coefficient examples
%drag=sparse(1:n,1:n,sin(x),n,n);
%freq=sparse(1:n,1:n,x-5,n,n);

bc=sparse([1 n],[1 n],[1 1],n,n);

%  Solve y'' - sin(x) y' + (x-5) y =0  y(0)=1, y(10)=0
%LHS= secderv-drag*derv+freq*ID + bc;
%  Solve y'' + 2y' + 3y = 0    y(0)=1,   y(10)=0
LHS= secderv+ 2*derv+ 3*ID + bc;

%full(LHS)

RHS=zeros(n,1);
RHS(1)=bcleft;
RHS(n)=bcright;

y_fd= LHS\RHS;
