function z=laplace_1d(u0)
%LAPLACE_1D Solves Laplace's Equation in one-dimension (i.e,
%   on a line segment) using a method which you should treat as a
%   "black box": you don't need to know how it works (even though it's
%   pretty obvious).  u0 defines both the size (length) of the grid as
%   well as the dirichlet boundary conditions on the ends.  The first
%   and last elements of u0 define the boundary conditions.  All other
%   values in the middle are ignored.
%
%   u0 should be a row vector.  However, if given more than
%   one row, it computes the solution for each row separately, so
%   one call to LAPLACE_1D can solve a bunch of intances of the
%   same-size 1D problem with different values on the boundary.
%
%   This function is analogous to the laplacefft function
%   that is given to you for this assignment.
%
%  $Id: laplace_1d.m,v 1.1 2004/03/31 07:47:37 kenta Exp $

last=size(u0,2);
s=last-1;
zero_to_one=(0:s)/s;
one_to_zero=(s:-1:0)/s;

%calculate the weighted average between the two endpoints.
z=u0(:,1)*one_to_zero + u0(:,last)*zero_to_one;
