function s  = SF(D,Fnct,u)
%------------------------------------------------------------ 
%//////////////////////////////////////////////////////////// 
%------------------------------------------------------------
%  Shape Functions
%    D = derivative
%      = 0 function itself
%      = 1 first derivative of function
%      = 2 second derivative of function
%      = 3 third derivative of function
%  Fnct= Shape function number
%    node = shape function number (1, 2, 3, or 4)
%       u = local coordinate
%------------------------------------------------------------

 if Fnct == 1  % Shape function 1
    if D == 0
       s = (1/4).*(u+2).*(u-1).^2;
    elseif D == 1
       s = (1/4).*(3.*u.^2-3);
    elseif D == 2
       s = (1/4)*(6*u);
    elseif D == 3
       s = (1/4)*(6);
    end

 elseif Fnct == 2  % Shape function 2
    if D == 0
       s = (1/4).*(u+1).*(u-1).^2;
       s = (1/4).*(1-u.^2).*(1-u);
    elseif D == 1
       s = (1/4)*(3*u.^2-2*u-1);
    elseif D == 2
       s = (1/4)*(6.*u-2);
    elseif D == 3
       s = (1/4)*(6);
    end

 elseif Fnct == 3  % Shape function 3
    if D == 0
       s = -(1/4).*(u-2).*(u+1).^2;
    elseif D == 1
       s = -(1/4)*(3*u.^2-3);
    elseif D == 2
       s = -(1/4)*(6*u);
    elseif D == 3
       s = -(1/4)*(6);
    end

 elseif Fnct == 4  % Shape function 4
    if D == 0
       s = (1/4)*(u-1).*(u+1).^2;
    elseif D == 1
       s = (1/4)*(3*u.^2+2*u-1);
    elseif D == 2
       s = (1/4)*(6*u+2);
    elseif D == 3
       s = (1/4)*(6);
    end
 end

