function [x,u] = lab02bvp(npts)
% [x,u] = lab02bvp(npts) computes the solution of
% the BVP: u''=-pi2/4*sin(pi*x/2)
% u(LEFT_X)=LEFT_U=0, u(RIGHT_X)=RIGHT_U=1
% using finite differences with npts points on
% a uniform mesh (with npts+1 intervals)
% npts is an integer value
% u is returned as a column vector
% x is returned as a row vector

% M. M. Sussman
% $Id: lab02bvp.m,v 1.1 2009/01/05 14:50:13 mike Exp $

LEFT_X=0;
LEFT_U=0;
RIGHT_X=1;
RIGHT_U=1;

A = zeros(npts,npts);
for k=1:npts
  if k<npts
    A(k+1,k)=1;
    A(k,k+1)=1;
  end
  A(k,k)=-2;
end
% npts interior mesh points, npts+1 intervals
dx = ( RIGHT_X - LEFT_X ) / ( npts + 1 );
x = dx * (1:npts);
b = dx^2*(-pi^2/4*sin(pi*x/2))';
b(1)=b(1) - LEFT_U;
b(npts)=b(npts) - RIGHT_U;
u = A \ b;
