% =======================================================================
% .. Derivation avec schemas optimises Bogey & Berland sur 11 pts
% =======================================================================
function [dudx] = gradient_cb2(u,x);

global cb2 a11dp

np = length(u);

ns = 5;
nx = np-2*ns;

dudx = 0.*u;
dxg  = 0.*u;


%.. computation of du/dx - stencil over 2*ns+1 pts with ns=5 and mesh of nx+2*ns pts

dudx(ns+1:ns+nx) = cb2(1)*(u(ns+2:ns+nx+1)-u(ns:ns+nx-1))    ...
                 + cb2(2)*(u(ns+3:ns+nx+2)-u(ns-1:ns+nx-2))  ...
                 + cb2(3)*(u(ns+4:ns+nx+3)-u(ns-2:ns+nx-3))  ...
                 + cb2(4)*(u(ns+5:ns+nx+4)-u(ns-3:ns+nx-4))  ...
                 + cb2(5)*(u(ns+6:ns+nx+5)-u(ns-4:ns+nx-5));           
             
dxg(ns+1:ns+nx) = cb2(1)*(x(ns+2:ns+nx+1)-x(ns:ns+nx-1))    ...
                + cb2(2)*(x(ns+3:ns+nx+2)-x(ns-1:ns+nx-2))  ...
                + cb2(3)*(x(ns+4:ns+nx+3)-x(ns-2:ns+nx-3))  ...
                + cb2(4)*(x(ns+5:ns+nx+4)-x(ns-3:ns+nx-4))  ...
                + cb2(5)*(x(ns+6:ns+nx+5)-x(ns-4:ns+nx-5)); 

            
%.. and treatment of boundary points             
             
dudx(1:ns) = a11dp(1:ns,1)*u(1) + a11dp(1:ns,2)*u(2)    ...
           + a11dp(1:ns,3)*u(3) + a11dp(1:ns,4)*u(4)    ...
           + a11dp(1:ns,5)*u(5) + a11dp(1:ns,6)*u(6)    ...
           + a11dp(1:ns,7)*u(7) + a11dp(1:ns,8)*u(8)    ...
           + a11dp(1:ns,9)*u(9) + a11dp(1:ns,10)*u(10)  ...
           + a11dp(1:ns,11)*u(11);

dxg(1:ns) = a11dp(1:ns,1)*x(1) + a11dp(1:ns,2)*x(2)    ...
          + a11dp(1:ns,3)*x(3) + a11dp(1:ns,4)*x(4)    ...
          + a11dp(1:ns,5)*x(5) + a11dp(1:ns,6)*x(6)    ...
          + a11dp(1:ns,7)*x(7) + a11dp(1:ns,8)*x(8)    ...
          + a11dp(1:ns,9)*x(9) + a11dp(1:ns,10)*x(10)  ...
          + a11dp(1:ns,11)*x(11);       

       
dudx(ns+nx+ns:-1:ns+nx+1) =                                    ...
           - a11dp(1:ns,1)*u(np)   - a11dp(1:ns,2)*u(np-1)  ...
           - a11dp(1:ns,3)*u(np-2) - a11dp(1:ns,4)*u(np-3)  ...
           - a11dp(1:ns,5)*u(np-4) - a11dp(1:ns,6)*u(np-5)  ...
           - a11dp(1:ns,7)*u(np-6) - a11dp(1:ns,8)*u(np-7)  ...
           - a11dp(1:ns,9)*u(np-8) - a11dp(1:ns,10)*u(np-9) ...
           - a11dp(1:ns,11)*u(np-10);                    

dxg(ns+nx+ns:-1:ns+nx+1) =                                    ...
           - a11dp(1:ns,1)*x(np)   - a11dp(1:ns,2)*x(np-1)  ...
           - a11dp(1:ns,3)*x(np-2) - a11dp(1:ns,4)*x(np-3)  ...
           - a11dp(1:ns,5)*x(np-4) - a11dp(1:ns,6)*x(np-5)  ...
           - a11dp(1:ns,7)*x(np-6) - a11dp(1:ns,8)*x(np-7)  ...
           - a11dp(1:ns,9)*x(np-8) - a11dp(1:ns,10)*x(np-9) ...
           - a11dp(1:ns,11)*x(np-10);

       
dudx = dudx ./dxg;

% =======================================================================
% =======================================================================
