function [x,u] = rope_bvp(npts)
% [x,u] = rope_bvp(npts) computes the solution of
% the hanging-rope BVP: u''=0.1, 
% u(LEFT_X)=LEFT_U, u(RIGHT_X)=RIGHT_U
% using finite differences with npts points on
% a uniform mesh (with npts+1 intervals)

% M. M. Sussman
% $Id: rope_bvp.m,v 1.2 2011/01/30 01:47:20 mike Exp $

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

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)';
rhs = 0.1 * dx^2;
b = rhs .* ones(npts,1);  % make a column vector
b(1)=b(1) - LEFT_U;
b(npts)=b(npts) - RIGHT_U;
u = A \ b;
