function [N, Mu, dN, dMu, dL, D, dD] = ieshape11m(xi,P,ptype,varargin)
%IESHAPE11M Calculates the shape functions of an 1D line infinite element
%   Inputs:
%       xi - N x 1 array of the gaussian integration points
%       P - polynomial order (positive scalar)
%       ptype - polynomial type (lagrange / jacobi)

% Process input depending on polynomial type
switch ptype
    % Lagrange polynomials
    case{1, 'l','lag','lagrange'}
        Lag = varargin{1};
        dLag = varargin{2};
    % Jacobian polynomials
    case{2, 'j','jac','jacobi'}
        a = varargin{1};
        b = varargin{2};
    otherwise
        error('ieshape22m:invalidArg','Unknown polynomial family.');
end

s = xi(:,1);
nxi = size(xi,1);

N = zeros(nxi,P);
Mu = zeros(nxi,P);
dN = zeros(1*nxi,P);
dD = zeros(1*nxi,P);
dL = zeros(1*nxi,2);
dMu = zeros(1*nxi,P);

switch ptype
    %Lagrange shape functions
    case {1, 'l','lag','lagrange'}
        for c1 = 1:P
            % Shape functions
            N(:,c1) = 1/2*(1-s).*polyval(Lag{c1},s);
            if nargout > 2
                % Derivative (d/ds)
                dN(:,c1) = 1/2*((-1)*polyval(Lag{c1},s)+(1-s).*polyval(dLag{c1},s));
            end
        end
    %Jacobi shape functions
    case {2, 'j','jac','jacobi'}
        for c1 = 1:P
            % Shape functions
            N(:,c1) = 1/2*(1-s).*jacpoly(c1-1,a,b,s);
            if nargout > 2
                % Derivative (d/ds)
                dN(:,c1) = 1/2*((-1)*jacpoly(c1-1,a,b,s)+(1-s).*djacpoly(c1-1,a,b,s,1));
            end
        end
end

if nargout > 1
    % Phase shape functions
    Mu(:,:,1) = repmat((1+s)./(1-s), 1, P);
end

if nargout > 3
    % Gradient of phase functions
    dMu = repmat(2./(s-1).^2,1,P);
end

if nargout > 4
    %Gradients of mapping functions
    dL(:,1) = -2 ./ (s-1).^2;
    dL(:,2) = 2 ./ (s-1).^2;
end

if nargout > 5
    %Weighting function
    D = repmat((1-s).^2/4,1,P);
end

if nargout > 6
    %Gradient of the weighting function
    dD = repmat(-1/2+1/2*s,1,P);   
end

end % of ieshape11m function

