function y=p_linear(x,bpts,vals)
%Computes a piecewise linear function with breakpoints BPTS 
%and corresponding values in VALS
if nargin==1,
   x1=min(x); 
   x3=max(x); 
   x2=(x1+x3)/2;
   bpts=[x1,x2,x3];
   vals=[0,1,0];
end
n=length(bpts)-1;
y=zeros(size(x));
m=diff(vals)./diff(bpts);
b=vals(1:n)-m.*bpts(1:n);
for ii=1:n,
   I=find(bpts(ii)<=x & x<bpts(ii+1));
   y(I)=polyval([m(ii),b(ii)],x(I));
end
