% quadrs2.m - Gauss-Legendre quadrature weights and evaluation points on subintervals
%
% Usage: [w,x] = quadrs2(ab,N)
%        [w,x] = quadrs2(ab)         (equivalent to N=16)
%
% ab = integration subintervals = [a0,a1,a2,...,aM]
% N  = number of weights in quadrature formula (default N=16), per subinterval
%
% w = length-(N*M) column vector of (symmetric) weights
% x = length-(N*M) column vector of shifted/scaled Legendre evaluation points 
%
% notes: the desired interval [a,b]=[a0,aM] is divided into M subintervals [a0,a1,...,aM]
%        and the weights/evaluation points of each subinterval are computed by QUADR 
%        and concatenated together, that is, 
%
%        w = [w1; w2; ...; wM], x = [x1; x2; ..., xM]
%
%        the desired integral over [a,b] is J = w'*f(x) = w1'*f(x1) + ... + wM'*f(xM)
%
%        substitute for QUADRS
%
% examples: [w,x] = quadrs2([1,2], 5);
%           [w,x] = quadrs2([1,1.5,2], 5);           
%           [w,x] = quadrs2(linspace(1,2,9), 5);
%
%           the operation: [w,x] = quadrs2([1,1.5,2], 5) is equivalent to:
%           [w1,x1] = quadr2(1,1.5,5); [w2,x2]=quadr2(1.5,2,5); w=[w1;w2]; x=[x1;x2]
%
%        see also QUADR2, QUADR, QUADRS

% Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa      

function [w,x] = quadrs(ab,N)

if nargin==0, help quadrs; return; end
if nargin==1, N=16; end

M = length(ab) - 1;

w = [];
x = [];

for i=1:M,
    [wi,xi] = quadr2(ab(i), ab(i+1), N);
    w = [w; wi];
    x = [x; xi];
end


