
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++ A full 3-D elastic model based on ++++++++++++;
%+++++++++ the depth-integrated momentum equations +++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


clear

dens=910; % ice dencity

dens_w=1000; % water dencity

g=9.81; 



LXSho=16000; % ice shelf extent in X-direction

LYSho=800;  % ice shelf extent in Y-derection

HGrl=100; % ice thickness at the grounding line

HShTerm=100; % ice thickness at the terminus


T_Cr=1800; % spatial periodicity of the crevasses

Depth_Cr=10; % the crevasses depth

Width_Cr=500; % the crevasses width



                              
E_Yung=9.0*10^9; % Young's modulus 

P_Puasson=0.33; % Poisson's ratio



Kp1=2*(1-P_Puasson)/(1-2*P_Puasson);

Kp2=2*P_Puasson/(1-2*P_Puasson);

KpE=2*(1+P_Puasson)/E_Yung;

KpE0=E_Yung/(1+P_Puasson);



Kpb1=(1-P_Puasson)/(1-2*P_Puasson);

Kpb2=P_Puasson/(1-2*P_Puasson);


alfa1=1.0; alfa2=0.0; % the parameters of the model (see in (Konovalov, 2019))

alfa12=alfa1+alfa2;


%----------------------;

PT0=125; % initial value of the periodicity of the vibrations

D_PT=0.2; % the periodicity resolution  

AmSLC=1.0; % the amplitude of the incident wave

NFreq=100; % the number of the main cycle repeats


%-------------------;

Nx=241;  % grid points number in X-direction (horizontal direction)

Ny=13; % grid points number in Y-derection (horizontal direction)

Nz=6; % grid points number in Z-derection (vertical direction)


dx=LXSho/(Nx-1); % the resolution in the X-direction

dy=1/(Ny-1); % the resolution in the Y-direction (non-dimensional)

dz=1/(Nz-1); % the resolution in the Z-direction (non-dimensional)

%++++++++++++++++++++++++ L_X, L_Y, L_Z +++++++++++++++++++++++;


L_X=zeros(1,Nx);  

for ii=1:1:Nx, L_X(ii)=dx*(ii-1); end


L_Y=zeros(1,Ny);  

for jj=1:1:Ny, L_Y(jj)=dy*(jj-1); end


L_Z=zeros(1,Nz); 

for kk=1:1:Nz, L_Z(kk)=dz*(kk-1); end



%+++ The interpolation parameters used in the procedure of the wavenumber obtaining +++;


Nx_interp=50*Nx;

dx_interp=LXSho/(Nx_interp-1);

L_X_interp=zeros(Nx_interp,1);

for ii=1:1:Nx_interp, L_X_interp(ii)=dx_interp*(ii-1); end


%---------------------------------------------;


%+++++ Ice Width in Y-direction (B), Y1(x), Y2(x), dB/dx ++++++++++++;

dfW=-1.0; % the difference between the ice width in y-direction at the grounding line and the one at the terminus

Wd1=LYSho; Wd2=LYSho+dfW;


Width=zeros(1,Nx); Y1=zeros(1,Nx); Y2=zeros(1,Nx);

for ii=1:1:Nx, Width(ii)=Wd1+((Wd2-Wd1)/LXSho)*L_X(ii); end

for ii=1:1:Nx, Y1(ii)=-0.5*(Wd1+((Wd2-Wd1)/LXSho)*L_X(ii)); end

for ii=1:1:Nx, Y2(ii)=0.5*(Wd1+((Wd2-Wd1)/LXSho)*L_X(ii)); end



%++++++ Ice Surface, Ice Base, Ice Thickness, Sea Bottom +++++++++++;

HIC0=zeros(Nx,Ny); 

for ii=1:1:Nx 
    for jj=1:1:Ny 
        HIC0(ii,jj)=HGrl+((HShTerm-HGrl)/LXSho)*L_X(ii);
    end 
end



HIC=zeros(Nx,Ny);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        HIC(ii,jj)=HIC0(ii,jj); 
    end 
end


%+++++++++++++++++++++++++++++++++++++++;
%++++++++ Rectangular Crevasses ++++++++;
%+++++++++++++++++++++++++++++++++++++++;

nn=1;

while (nn*T_Cr+Width_Cr/2)<LXSho
    
    for ii=1:1:Nx
        for jj=1:1:Ny
            if (L_X(ii)>(nn*T_Cr-Width_Cr/2)) && (L_X(ii)<(nn*T_Cr+Width_Cr/2))
                HIC(ii,jj)=HIC(ii,jj)-Depth_Cr*(dens_w/dens);
            end
        end
    end
    
    N_Cr=nn;
    
    nn=nn+1;
        
end


%++++++++++++++++++++++++++++++++++++++;
%++++++++ Triangular Crevasses ++++++++;
%++++++++++++++++++++++++++++++++++++++;


% nn=1;
% 
% while (nn*T_Cr + Width_Cr/2)<LXSho
%     
%     for ii=1:1:Nx
%         for jj=1:1:Ny
%             
%             if (L_X(ii)>(nn*T_Cr - Width_Cr/2)) && (L_X(ii)<=nn*T_Cr)
%                 HIC(ii,jj)=HIC(ii,jj)-(2*Depth_Cr/Width_Cr)*(L_X(ii)-(nn*T_Cr-Width_Cr/2))*(dens_w/dens);
%             end
%             
%             if (L_X(ii)>nn*T_Cr) && (L_X(ii)<(nn*T_Cr+Width_Cr/2))
%                 HIC(ii,jj)=HIC(ii,jj)-((-2*Depth_Cr/Width_Cr)*(L_X(ii)-(nn*T_Cr-Width_Cr/2))+2*Depth_Cr)*(dens_w/dens);
%             end
%             
%         end
%     end
%     
%     N_Cr=nn;
%     
%     nn=nn+1;
%         
% end


%-----------------------------------------------;

HSF0=zeros(Nx,Ny);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        HSF0(ii,jj)=HIC0(ii,jj)*(1-dens/dens_w); 
    end 
end


HSF=zeros(Nx,Ny);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        HSF(ii,jj)=HIC(ii,jj)*(1-dens/dens_w); 
    end 
end


%------------------------------------------------;

HBF0=zeros(Nx,Ny);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        HBF0(ii,jj)=-HIC0(ii,jj)*(dens/dens_w); 
    end 
end


HBF=zeros(Nx,Ny);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        HBF(ii,jj)=-HIC(ii,jj)*(dens/dens_w); 
    end 
end

%---------------------------------------------------;

HBSEA=zeros(Nx,Ny); 

C_depth_GrL=100; C_depth_Term=100; % The water channel depth at the grounding line and at the terminus, respectivelly;

for ii=1:1:Nx
    for jj=1:1:Ny 
        HBSEA(ii,jj)=HBF0(1,jj)-C_depth_GrL + (((HBF0(Nx,jj)-C_depth_Term)-(HBF0(1,jj)-C_depth_GrL))/LXSho)*L_X(ii); 
    end
end


WDepth_ij=zeros(Nx,Ny);

for ii=1:1:Nx
    for jj=1:1:Ny 
        WDepth_ij(ii,jj)=HBF(ii,jj)-HBSEA(ii,jj); 
    end 
end


%------------------------------------------------;

figure(1);

%surf(L_X./LXSho,L_Y,HBF'), title('Ice Shelf Base'), xlabel('X, m'), ylabel('Y, m'), zlabel('Elevation, m')

surf(L_X,L_Y.*LYSho,HBF'), title('Ice Shelf Base'), xlabel('X, m'), ylabel('Y, m'), zlabel('Elevation, m')

%contourf(L_X./Lo,L_Y,HBF), title('Ice Sheet Bed'), xlabel('X, m'), ylabel('Y, m')

figure(2);

%surf(L_X./LXSho,L_Y,HSF'), title('Ice Shelf Surface'), xlabel('X, m'), ylabel('Y, m'), zlabel('Elevation, m')

surf(L_X,L_Y.*LYSho,HSF'), title('Ice Shelf Surface'), xlabel('X, m'), ylabel('Y, m'), zlabel('Elevation, m')

%contourf(L_X./Lo,L_Y,HSF), title('Ice Sheet Surface'), xlabel('X, m'), ylabel('Y, m')

figure(3);

%surf(L_X./LXSho,L_Y,HBSEA'), title('Sea Bottom'), xlabel('X, m'), ylabel('Y, m'), zlabel('Elevation, m')

surf(L_X,L_Y.*LYSho,HBSEA'), title('Sea Bottom'), xlabel('X, m'), ylabel('Y, m'), zlabel('Elevation, m')

%contourf(L_X./Lo,L_Y,HSF), title('Ice Sheet Surface'), xlabel('X, m'), ylabel('Y, m')



LP_HSF=zeros(1,Nx); LP_HBF=zeros(1,Nx); LP_HBSEA=zeros(1,Nx); LP_HIC=zeros(1,Nx); LP_WDepth=zeros(1,Nx);

Jy=round(Ny/2)+1;

for ii=1:1:Nx, LP_HSF(ii)=HSF(ii,Jy); end

for ii=1:1:Nx, LP_HBF(ii)=HBF(ii,Jy); end

for ii=1:1:Nx, LP_HBSEA(ii)=HBSEA(ii,Jy); end

for ii=1:1:Nx, LP_HIC(ii)=HIC(ii,Jy); end

for ii=1:1:Nx, LP_WDepth(ii)=WDepth_ij(ii,Jy); end


figure(4);

plot(L_X,LP_HSF,'-b.',L_X,LP_HBF,'-rd',L_X,LP_HBSEA,'-k.'), title('Ice Shelf Centre Line Cross-section'), legend('Ice Shelf Surface','Ice Shelf Base','Sea Bottom'), xlabel('X, m'), ylabel('Elevation, m'), grid


figure(5);

plot(L_X,LP_HIC,'-b.',L_X,LP_WDepth,'-rd'), title('Ice Shelf Centre Line Thickness'), legend('Ice Shelf Thickness','Water Channel Depth'), xlabel('X, m'), ylabel('Thickness, m'), grid



%-------------- dB/dx, dY1/dx, dY2/dx -----------------;

difWd=zeros(1,Nx);

difWd(1)=(Width(2)-Width(1))/dx;
for ii=2:1:Nx-1, difWd(ii)=(Width(ii+1)-Width(ii-1))/(2*dx); end
difWd(Nx)=(Width(Nx)-Width(Nx-1))/dx;


difY1=zeros(1,Nx);

difY1(1)=(Y1(2)-Y1(1))/dx;
for ii=2:1:Nx-1, difY1(ii)=(Y1(ii+1)-Y1(ii-1))/(2*dx); end
difY1(Nx)=(Y1(Nx)-Y1(Nx-1))/dx;


difY2=zeros(1,Nx);

difY2(1)=(Y2(2)-Y2(1))/dx;
for ii=2:1:Nx-1, difY2(ii)=(Y2(ii+1)-Y2(ii-1))/(2*dx); end
difY2(Nx)=(Y2(Nx)-Y2(Nx-1))/dx;


%+++++++++++++++++++++++++++ dQ/dx, dQ/dy +++++++++++++++++++++++++++++++;

dQx=zeros(Nx,Ny);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        dQx(ii,jj)=-(1/Width(ii))*(difY1(ii)+L_Y(jj)*difWd(ii)); 
    end 
end


dQy=zeros(Nx,1);

for ii=1:1:Nx, dQy(ii)=1/Width(ii); end



%++++++++++++++++++++++++ dHs/dx, dHs/dy +++++++++++++++++++++++++++++;

dHsx=zeros(Nx,Ny); dHsy=zeros(Nx,Ny);


%--------------------- dHs/dx -----------------------;

dHsx(1,1)=(-HSF(3,1)+4*HSF(2,1)-3*HSF(1,1))/(2*dx)+((-HSF(1,3)+4*HSF(1,2)-3*HSF(1,1))/(2*dy))*dQx(1,1);

for jj=2:1:Ny-1 
    dHsx(1,jj)=(-HSF(3,jj)+4*HSF(2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ii,1))/(2*dy))*dQy(ii); end

for ii=1:1:Nx 
    for jj=2:1:Ny-1 
        dHsy(ii,jj)=((HSF(ii,jj+1)-HSF(ii,jj-1))/(2*dy))*dQy(ii); 
    end 
end

for ii=1:1:Nx, dHsy(ii,Ny)=((3*HSF(ii,Ny)-4*HSF(ii,Ny-1)+HSF(ii,Ny-2))/(2*dy))*dQy(ii); end



%++++++++++++++++++++++++ dHb/dx, dHb/dy +++++++++++++++++++++++++++++;

dHbx=zeros(Nx,Ny); dHby=zeros(Nx,Ny);


%--------------------------- dHb/dx ----------------------------;

dHbx(1,1)=(-HBF(3,1)+4*HBF(2,1)-3*HBF(1,1))/(2*dx)+((-HBF(1,3)+4*HBF(1,2)-3*HBF(1,1))/(2*dy))*dQx(1,1);

for jj=2:1:Ny-1 
    dHbx(1,jj)=(-HBF(3,jj)+4*HBF(2,jj)-3*HBF(1,jj))/(2*dx)+((HBF(1,jj+1)-HBF(1,jj-1))/(2*dy))*dQx(1,jj); 
end

dHbx(1,Ny)=(-HBF(3,Ny)+4*HBF(2,Ny)-3*HBF(1,Ny))/(2*dx)+((3*HBF(1,Ny)-4*HBF(1,Ny-1)+HBF(1,Ny-2))/(2*dy))*dQx(1,Ny);

for ii=2:1:Nx-1 
    dHbx(ii,1)=(HBF(ii+1,1)-HBF(ii-1,1))/(2*dx)+((-HBF(ii,3)+4*HBF(ii,2)-3*HBF(ii,1))/(2*dy))*dQx(ii,1);
end 

for ii=2:1:Nx-1 
    for jj=2:1:Ny-1 
        dHbx(ii,jj)=(HBF(ii+1,jj)-HBF(ii-1,jj))/(2*dx)+((HBF(ii,jj+1)-HBF(ii,jj-1))/(2*dy))*dQx(ii,jj); 
    end 
end

for ii=2:1:Nx-1 
    dHbx(ii,Ny)=(HBF(ii+1,Ny)-HBF(ii-1,Ny))/(2*dx)+((3*HBF(ii,Ny)-4*HBF(ii,Ny-1)+HBF(ii,Ny-2))/(2*dy))*dQx(ii,Ny); 
end

dHbx(Nx,1)=(3*HBF(Nx,1)-4*HBF(Nx-1,1)+HBF(Nx-2,1))/(2*dx)+((-HBF(Nx,3)+4*HBF(Nx,2)-3*HBF(Nx,1))/(2*dy))*dQx(Nx,1);

for jj=2:1:Ny-1 
    dHbx(Nx,jj)=(3*HBF(Nx,jj)-4*HBF(Nx-1,jj)+HBF(Nx-2,jj))/(2*dx)+((HBF(Nx,jj+1)-HBF(Nx,jj-1))/(2*dy))*dQx(Nx,jj); 
end

dHbx(Nx,Ny)=(3*HBF(Nx,Ny)-4*HBF(Nx-1,Ny)+HBF(Nx-2,Ny))/(2*dx)+((3*HBF(Nx,Ny)-4*HBF(Nx,Ny-1)+HBF(Nx,Ny-2))/(2*dy))*dQx(Nx,Ny);

%-------------------- dHb/dy ----------------------;

for ii=1:1:Nx, dHby(ii,1)=((-HBF(ii,3)+4*HBF(ii,2)-3*HBF(ii,1))/(2*dy))*dQy(ii); end

for ii=1:1:Nx 
    for jj=2:1:Ny-1 
        dHby(ii,jj)=((HBF(ii,jj+1)-HBF(ii,jj-1))/(2*dy))*dQy(ii); 
    end 
end

for ii=1:1:Nx, dHby(ii,Ny)=((3*HBF(ii,Ny)-4*HBF(ii,Ny-1)+HBF(ii,Ny-2))/(2*dy))*dQy(ii); end



%++++++++++++++++++++++++ dH/dx, dH/dy +++++++++++++++++++++++++++++;

dHx=zeros(Nx,Ny); dHy=zeros(Nx,Ny);


%------------------ dH/dx --------------------;

dHx(1,1)=(-HIC(3,1)+4*HIC(2,1)-3*HIC(1,1))/(2*dx)+((-HIC(1,3)+4*HIC(1,2)-3*HIC(1,1))/(2*dy))*dQx(1,1);

for jj=2:1:Ny-1 
    dHx(1,jj)=(-HIC(3,jj)+4*HIC(2,jj)-3*HIC(1,jj))/(2*dx)+((HIC(1,jj+1)-HIC(1,jj-1))/(2*dy))*dQx(1,jj); 
end

dHx(1,Ny)=(-HIC(3,Ny)+4*HIC(2,Ny)-3*HIC(1,Ny))/(2*dx)+((3*HIC(1,Ny)-4*HIC(1,Ny-1)+HIC(1,Ny-2))/(2*dy))*dQx(1,Ny);

for ii=2:1:Nx-1 
    dHx(ii,1)=(HIC(ii+1,1)-HIC(ii-1,1))/(2*dx)+((-HIC(ii,3)+4*HIC(ii,2)-3*HIC(ii,1))/(2*dy))*dQx(ii,1);
end 

for ii=2:1:Nx-1 
    for jj=2:1:Ny-1 
        dHx(ii,jj)=(HIC(ii+1,jj)-HIC(ii-1,jj))/(2*dx)+((HIC(ii,jj+1)-HIC(ii,jj-1))/(2*dy))*dQx(ii,jj); 
    end 
end

for ii=2:1:Nx-1 
    dHx(ii,Ny)=(HIC(ii+1,Ny)-HIC(ii-1,Ny))/(2*dx)+((3*HIC(ii,Ny)-4*HIC(ii,Ny-1)+HIC(ii,Ny-2))/(2*dy))*dQx(ii,Ny); 
end

dHx(Nx,1)=(3*HIC(Nx,1)-4*HIC(Nx-1,1)+HIC(Nx-2,1))/(2*dx)+((-HIC(Nx,3)+4*HIC(Nx,2)-3*HIC(Nx,1))/(2*dy))*dQx(Nx,1);

for jj=2:1:Ny-1 
    dHx(Nx,jj)=(3*HIC(Nx,jj)-4*HIC(Nx-1,jj)+HIC(Nx-2,jj))/(2*dx)+((HIC(Nx,jj+1)-HIC(Nx,jj-1))/(2*dy))*dQx(Nx,jj); 
end

dHx(Nx,Ny)=(3*HIC(Nx,Ny)-4*HIC(Nx-1,Ny)+HIC(Nx-2,Ny))/(2*dx)+((3*HIC(Nx,Ny)-4*HIC(Nx,Ny-1)+HIC(Nx,Ny-2))/(2*dy))*dQx(Nx,Ny);


%-------------------- dH/dy ----------------------;

for ii=1:1:Nx, dHy(ii,1)=((-HIC(ii,3)+4*HIC(ii,2)-3*HIC(ii,1))/(2*dy))*dQy(ii); end

for ii=1:1:Nx 
    for jj=2:1:Ny-1 
        dHy(ii,jj)=((HIC(ii,jj+1)-HIC(ii,jj-1))/(2*dy))*dQy(ii); 
    end 
end

for ii=1:1:Nx, dHy(ii,Ny)=((3*HIC(ii,Ny)-4*HIC(ii,Ny-1)+HIC(ii,Ny-2))/(2*dy))*dQy(ii); end



%++++++++++++++++++++++ dZ/dx, dZ/dy, dZ/dz +++++++++++++++++++++++++;

dZx=zeros(Nx,Ny,Nz);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        for kk=1:1:Nz 
            dZx(ii,jj,kk)=dHsx(ii,jj)/HIC(ii,jj)-dHx(ii,jj)*L_Z(kk)/HIC(ii,jj);
        end 
    end
end 


dZy=zeros(Nx,Ny,Nz);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        for kk=1:1:Nz 
            dZy(ii,jj,kk)=dHsy(ii,jj)/HIC(ii,jj)-dHy(ii,jj)*L_Z(kk)/HIC(ii,jj); 
        end 
    end
end


dZz=zeros(Nx,Ny);

for ii=1:1:Nx 
    for jj=1:1:Ny 
        dZz(ii,jj)=-1/HIC(ii,jj); 
    end 
end


%+++++++++++++++++++++++++ Arrays +++++++++++++++++++++++++++++++;


data_U0=zeros(Ny,Nz);
data_ULE1=zeros(Nx,Nz);
data_ULE2=zeros(Nx,Nz);
data_UN=zeros(Ny,Nz);

data_V0=zeros(Ny,Nz);
data_VLE1=zeros(Nx,Nz);
data_VLE2=zeros(Nx,Nz);
data_VN=zeros(Ny,Nz);

data_W0=zeros(Ny,Nz);
data_WLE1=zeros(Nx,Nz);
data_WLE2=zeros(Nx,Nz);
data_WN=zeros(Ny,Nz);

masU=zeros(Nx,Ny,Nz);
masV=zeros(Nx,Ny,Nz);
masW=zeros(Nx,Ny,Nz);


Delta_H=zeros(Nx,Ny,NFreq);
Delta_Ws=zeros(Nx,Ny,NFreq);
Delta_P=zeros(Nx,Ny,NFreq);

Delta_HX=zeros(Nx,1);


L_X_node_max=zeros(Nx,1);

L_X_node_min=zeros(Nx,1);

%---------------------------;

GpHInt1_ij=zeros(Nx,Ny);
GpHdQInt2_ij=zeros(Nx,Ny);
GpHdQInt3_ij=zeros(Nx,Ny);

%---------------------------;
 
 d1Hx=zeros(Nx,Ny);
 d1Hq=zeros(Nx,Ny);
 
 d2QxHx=zeros(Nx,Ny);
 d2QxHq=zeros(Nx,Ny);
 d2QyHx=zeros(Nx,Ny);
 d2QyHq=zeros(Nx,Ny);
 
 d2Y1xHx=zeros(Nx,Ny);
 d2Y2xHx=zeros(Nx,Ny);
 
 d2QxHY1x=zeros(Nx,Ny);
 d2QyHY1x=zeros(Nx,Ny);
 
 d2QxHY2x=zeros(Nx,Ny);
 d2QyHY2x=zeros(Nx,Ny);


 d2Zxz=zeros(Nx,Ny,Nz);

 d2Zyz=zeros(Nx,Ny,Nz);
 

 WDx_ij=zeros(Nx,Ny);
 WDy_ij=zeros(Nx,Ny);
 WDQxx_ij=zeros(Nx,Ny);
 WDQxy_ij=zeros(Nx,Ny);
 WDQx2y_ij=zeros(Nx,Ny);
 WWx_i=zeros(Nx,1);

%----------------------------;

 max_Delta_H=zeros(NFreq,1);

 Length_Wave=zeros(NFreq,1);

 Wavenumber=zeros(NFreq,1);

%------------------------------------------------------------------;

 MB=zeros(3*Nx*Ny*Nz+2*Nx*Ny);

 VB=zeros(3*Nx*Ny*Nz+2*Nx*Ny,1);


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

for ii=2:1:Nx 
for jj=1:1:Ny 
GpHInt1_ij(ii,jj)=(HIC(ii-1,jj)+HIC(ii,jj))/2;
end
end


for ii=1:1:Nx 
for jj=2:1:Ny 
GpHdQInt2_ij(ii,jj)=(HIC(ii,jj-1)*dQx(ii,jj-1)+HIC(ii,jj)*dQx(ii,jj))/2;
end
end


for ii=1:1:Nx 
for jj=2:1:Ny 
GpHdQInt3_ij(ii,jj)=(HIC(ii,jj-1)*dQy(ii)+HIC(ii,jj)*dQy(ii))/2;
end
end



for ii=2:1:Nx 
for jj=1:1:Ny
WDx_ij(ii,jj)=(WDepth_ij(ii-1,jj)+WDepth_ij(ii,jj))/2;
end
end

for ii=1:1:Nx 
for jj=2:1:Ny
WDy_ij(ii,jj)=(WDepth_ij(ii,jj-1)+WDepth_ij(ii,jj))/2;
end
end


for ii=2:1:Nx 
for jj=1:1:Ny
WDQxx_ij(ii,jj)=(WDepth_ij(ii-1,jj)*dQx(ii-1,jj)+WDepth_ij(ii,jj)*dQx(ii,jj))/2;
end
end


for ii=1:1:Nx 
for jj=2:1:Ny
WDQxy_ij(ii,jj)=(WDepth_ij(ii,jj-1)*dQx(ii,jj-1)+WDepth_ij(ii,jj)*dQx(ii,jj))/2;
end
end


for ii=1:1:Nx 
for jj=2:1:Ny
WDQx2y_ij(ii,jj)=(WDepth_ij(ii,jj-1)*dQx(ii,jj-1)^2+WDepth_ij(ii,jj)*dQx(ii,jj)^2)/2;
end
end


for ii=2:1:Nx 
WWx_i(ii)=(Width(ii-1)+Width(ii))/2;
end


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

for jj=1:1:Ny, d1Hx(1,jj)=(-3*HIC(1,jj)+4*HIC(2,jj)-HIC(3,jj))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d1Hx(ii,jj)=(HIC(ii+1,jj)-HIC(ii-1,jj))/(2*dx);
end
end

for jj=1:1:Ny, d1Hx(Nx,jj)=(3*HIC(Nx,jj)-4*HIC(Nx-1,jj)+HIC(Nx-2,jj))/(2*dx); end

%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

for ii=1:1:Nx, d1Hq(ii,1)=(-3*HIC(ii,1)+4*HIC(ii,2)-HIC(ii,3))/(2*dy); end 

for ii=1:1:Nx
for jj=2:1:Ny-1
    d1Hq(ii,jj)=(HIC(ii,jj+1)-HIC(ii,jj-1))/(2*dy);
end
end

for ii=1:1:Nx, d1Hq(ii,Ny)=(3*HIC(ii,Ny)-4*HIC(ii,Ny-1)+HIC(ii,Ny-2))/(2*dy); end 


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2QxHx(1,jj)=(-3*dQx(1,jj)*HIC(1,jj)+4*dQx(2,jj)*HIC(2,jj)-dQx(3,jj)*HIC(3,jj))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2QxHx(ii,jj)=(dQx(ii+1,jj)*HIC(ii+1,jj)-dQx(ii-1,jj)*HIC(ii-1,jj))/(2*dx);
end
end

for jj=1:1:Ny, d2QxHx(Nx,jj)=(3*dQx(Nx,jj)*HIC(Nx,jj)-4*dQx(Nx-1,jj)*HIC(Nx-1,jj)+dQx(Nx-2,jj)*HIC(Nx-2,jj))/(2*dx); end 


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for ii=1:1:Nx, d2QxHq(ii,1)=(-3*dQx(ii,1)*HIC(ii,1)+4*dQx(ii,2)*HIC(ii,2)-dQx(ii,3)*HIC(ii,3))/(2*dy); end 

for ii=1:1:Nx
for jj=2:1:Ny-1
    d2QxHq(ii,jj)=(dQx(ii,jj+1)*HIC(ii,jj+1)-dQx(ii,jj-1)*HIC(ii,jj-1))/(2*dy);
end
end

for ii=1:1:Nx, d2QxHq(ii,Ny)=(3*dQx(ii,Ny)*HIC(ii,Ny)-4*dQx(ii,Ny-1)*HIC(ii,Ny-1)+dQx(ii,Ny-2)*HIC(ii,Ny-2))/(2*dy); end 


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2QyHx(1,jj)=(-3*dQy(1)*HIC(1,jj)+4*dQy(2)*HIC(2,jj)-dQy(3)*HIC(3,jj))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2QyHx(ii,jj)=(dQy(ii+1)*HIC(ii+1,jj)-dQy(ii-1)*HIC(ii-1,jj))/(2*dx);
end
end

for jj=1:1:Ny, d2QyHx(Nx,jj)=(3*dQy(Nx)*HIC(Nx,jj)-4*dQy(Nx-1)*HIC(Nx-1,jj)+dQy(Nx-2)*HIC(Nx-2,jj))/(2*dx); end


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for ii=1:1:Nx, d2QyHq(ii,1)=(-3*dQy(ii)*HIC(ii,1)+4*dQy(ii)*HIC(ii,2)-dQy(ii)*HIC(ii,3))/(2*dy); end 

for ii=1:1:Nx
for jj=2:1:Ny-1
    d2QyHq(ii,jj)=(dQy(ii)*HIC(ii,jj+1)-dQy(ii)*HIC(ii,jj-1))/(2*dy);
end
end

for ii=1:1:Nx, d2QyHq(ii,Ny)=(3*dQy(ii)*HIC(ii,Ny)-4*dQy(ii)*HIC(ii,Ny-1)+dQy(ii)*HIC(ii,Ny-2))/(2*dy); end


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2Y1xHx(1,jj)=(-3*difY1(1)*HIC(1,jj)+4*difY1(2)*HIC(2,jj)-difY1(3)*HIC(3,jj))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2Y1xHx(ii,jj)=(difY1(ii+1)*HIC(ii+1,jj)-difY1(ii-1)*HIC(ii-1,jj))/(2*dx);
end
end

for jj=1:1:Ny, d2Y1xHx(Nx,jj)=(3*difY1(Nx)*HIC(Nx,jj)-4*difY1(Nx-1)*HIC(Nx-1,jj)+difY1(Nx-2)*HIC(Nx-2,jj))/(2*dx); end


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2Y2xHx(1,jj)=(-3*difY2(1)*HIC(1,jj)+4*difY2(2)*HIC(2,jj)-difY2(3)*HIC(3,jj))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2Y2xHx(ii,jj)=(difY2(ii+1)*HIC(ii+1,jj)-difY2(ii-1)*HIC(ii-1,jj))/(2*dx);
end
end

for jj=1:1:Ny, d2Y2xHx(Nx,jj)=(3*difY2(Nx)*HIC(Nx,jj)-4*difY2(Nx-1)*HIC(Nx-1,jj)+difY2(Nx-2)*HIC(Nx-2,jj))/(2*dx); end



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2QxHY1x(1,jj)=(-3*dQx(1,jj)*HIC(1,jj)*difY1(1)+4*dQx(2,jj)*HIC(2,jj)*difY1(2)-dQx(3,jj)*HIC(3,jj)*difY1(3))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2QxHY1x(ii,jj)=(dQx(ii+1,jj)*HIC(ii+1,jj)*difY1(ii+1)-dQx(ii-1,jj)*HIC(ii-1,jj)*difY1(ii-1))/(2*dx);
end
end

for jj=1:1:Ny, d2QxHY1x(Nx,jj)=(3*dQx(Nx,jj)*HIC(Nx,jj)*difY1(Nx)-4*dQx(Nx-1,jj)*HIC(Nx-1,jj)*difY1(Nx-1)+dQx(Nx-2,jj)*HIC(Nx-2,jj)*difY1(Nx-2))/(2*dx); end


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2QxHY2x(1,jj)=(-3*dQx(1,jj)*HIC(1,jj)*difY2(1)+4*dQx(2,jj)*HIC(2,jj)*difY2(2)-dQx(3,jj)*HIC(3,jj)*difY2(3))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2QxHY2x(ii,jj)=(dQx(ii+1,jj)*HIC(ii+1,jj)*difY2(ii+1)-dQx(ii-1,jj)*HIC(ii-1,jj)*difY2(ii-1))/(2*dx);
end
end

for jj=1:1:Ny, d2QxHY2x(Nx,jj)=(3*dQx(Nx,jj)*HIC(Nx,jj)*difY2(Nx)-4*dQx(Nx-1,jj)*HIC(Nx-1,jj)*difY2(Nx-1)+dQx(Nx-2,jj)*HIC(Nx-2,jj)*difY2(Nx-2))/(2*dx); end



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2QyHY1x(1,jj)=(-3*dQy(1)*HIC(1,jj)*difY1(1)+4*dQy(2)*HIC(2,jj)*difY1(2)-dQy(3)*HIC(3,jj)*difY1(3))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2QyHY1x(ii,jj)=(dQy(ii+1)*HIC(ii+1,jj)*difY1(ii+1)-dQy(ii-1)*HIC(ii-1,jj)*difY1(ii-1))/(2*dx);
end
end

for jj=1:1:Ny, d2QyHY1x(Nx,jj)=(3*dQy(Nx)*HIC(Nx,jj)*difY1(Nx)-4*dQy(Nx-1)*HIC(Nx-1,jj)*difY1(Nx-1)+dQy(Nx-2)*HIC(Nx-2,jj)*difY1(Nx-2))/(2*dx); end


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=1:1:Ny, d2QyHY2x(1,jj)=(-3*dQy(1)*HIC(1,jj)*difY2(1)+4*dQy(2)*HIC(2,jj)*difY2(2)-dQy(3)*HIC(3,jj)*difY2(3))/(2*dx); end 

for ii=2:1:Nx-1
for jj=1:1:Ny
    d2QyHY2x(ii,jj)=(dQy(ii+1)*HIC(ii+1,jj)*difY2(ii+1)-dQy(ii-1)*HIC(ii-1,jj)*difY2(ii-1))/(2*dx);
end
end

for jj=1:1:Ny, d2QyHY2x(Nx,jj)=(3*dQy(Nx)*HIC(Nx,jj)*difY2(Nx)-4*dQy(Nx-1)*HIC(Nx-1,jj)*difY2(Nx-1)+dQy(Nx-2)*HIC(Nx-2,jj)*difY2(Nx-2))/(2*dx); end


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

for ii=1:1:Nx
for jj=1:1:Ny
for kk=1:1:Nz
    d2Zxz(ii,jj,kk)=-dHx(ii,jj)/HIC(ii,jj);
end
end
end
 
 
for ii=1:1:Nx
for jj=1:1:Ny
for kk=1:1:Nz
    d2Zyz(ii,jj,kk)=-dHy(ii,jj)/HIC(ii,jj);
end
end
end


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++++ THE MAIN CYCLE START +++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;



for JFreq=1:1:NFreq

%-------------------------------;

MB=zeros(3*Nx*Ny*Nz+2*Nx*Ny);

VB=zeros(3*Nx*Ny*Nz+2*Nx*Ny,1);

%------------------------------;

Freq=2*pi/(PT0+JFreq*D_PT); % frequency of the vibrations


%++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++ BOUNDARY CONDITIONS ++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++;



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++++++ Ix=1 (X=0) +++++++++++++++++++++++++;
%++++++++++ deformations at the grounding line +++++++++++++;
% In the model the boundary is considered as fixed boundary ;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

%-------------- (U=0) ----------------;

for jj=1:1:Ny
for kk=1:1:Nz 
MB((jj-1)*Nz+kk,(jj-1)*Nz+kk)=1; 
end 
end

% for jj=1:1:Ny
% for kk=1:1:Nz 
% VB((jj-1)*Nz+kk)=0; 
% end 
% end

%-------------- (V=0) ----------------;

for jj=1:1:Ny
for kk=1:1:Nz 
MB(Nx*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(jj-1)*Nz+kk)=1; 
end 
end

% for jj=1:1:Ny
% for kk=1:1:Nz 
% VB(Nx*Ny*Nz+(jj-1)*Nz+kk)=0; 
% end 
% end

%-------------- (W=0) ----------------;

for jj=1:1:Ny
for kk=1:1:Nz 
MB(2*Nx*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(jj-1)*Nz+kk)=1; 
end 
end

% for jj=1:1:Ny
% for kk=1:1:Nz 
% VB(2*Nx*Ny*Nz+(jj-1)*Nz+kk)=0; 
% end 
% end



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++ Ice Shelf Terminus: Ix=Nx (X=LXSho) +++++++++++++;
%+++++++++++++++++++++ (free edge) +++++++++++++++++++++++++;



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++ Basic Boundary Conditions at the terminus +++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++ The first equation ( basic equation #1) ++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++ KpE Fxx +++++++++++++++++;

%---------------- Kp1 dU/dx --------------;

for jj=2:1:Ny-1
for kk=2:1:Nz                                              
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)+ alfa1*Kp1*(1/(2*dx));
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)+alfa1*Kp1*(-4/(2*dx));
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+ alfa1*Kp1*(3/(2*dx));                                                      
end 
end


%-------------- Kp1 dQx dU/dQ -----------;

for jj=2:1:Ny-1
for kk=2:1:Nz                                              
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)+alfa1*Kp1*(-1/(2*dy))*dQx(Nx,jj);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)+     alfa1*Kp1*(1/(2*dy))*dQx(Nx,jj);                                                      
end 
end


%-------------- Kp1 dZx dU/dz -----------;

for jj=2:1:Ny-1
for kk=2:1:Nz-1                                              
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk-1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk-1)+alfa1*Kp1*(-1/(2*dz))*dZx(Nx,jj,kk);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk+1)+ alfa1*Kp1*(1/(2*dz))*dZx(Nx,jj,kk);                                                      
end 
end

for jj=2:1:Ny-1
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-2)+ alfa1*Kp1*(1/(2*dz))*dZx(Nx,jj,Nz); 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)+alfa1*Kp1*(-4/(2*dz))*dZx(Nx,jj,Nz);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)=  MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)+   alfa1*Kp1*(3/(2*dz))*dZx(Nx,jj,Nz);                                                      
end 



%-------------- Kp2 dQy dV/dQ -----------;

for jj=2:1:Ny-1
for kk=2:1:Nz                                              
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)+alfa1*Kp2*(-1/(2*dy))*dQy(Nx);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+jj*Nz+kk)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+jj*Nz+kk)+     alfa1*Kp2*(1/(2*dy))*dQy(Nx);                                                      
end 
end


%-------------- Kp2 dZy dV/dz -----------;

for jj=2:1:Ny-1
for kk=2:1:Nz-1                                              
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk-1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk-1)+alfa1*Kp2*(-1/(2*dz))*dZy(Nx,jj,kk);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk+1)+ alfa1*Kp2*(1/(2*dz))*dZy(Nx,jj,kk);                                                      
end 
end

for jj=2:1:Ny-1
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-2)+ alfa1*Kp2*(1/(2*dz))*dZy(Nx,jj,Nz); 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*N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Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)+alfa1*Kp2*(-4/(2*dz))*dZz(Nx,jj);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)=  MB((Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)+   alfa1*Kp2*(3/(2*dz))*dZz(Nx,jj);                                                      
end 




%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++ The second equation (basic equation #2) +++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++ KpE Fyx ++++++++++++++++++++;

%------------------ dQy dU/dQ -------------------;

for jj=2:1:Ny-1
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)+alfa1*(-1/(2*dy))*dQy(Nx);            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)+     alfa1*(1/(2*dy))*dQy(Nx);                                                      
end 
end


%------------------ dZy dU/dz -------------------;

for jj=2:1:Ny-1
for kk=2:1:Nz-1                                              
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk-1)=MB(Nx*Ny*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)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)+ alfa1*(1/(2*dx));
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)+alfa1*(-4/(2*dx));
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+ alfa1*(3/(2*dx));                                        
end 
end

%----------------- dQx dV/dQ -------------------;

for jj=2:1:Ny-1
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)+alfa1*(-1/(2*dy))*dQx(Nx,jj);            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+jj*Nz+kk)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+jj*Nz+kk)+     alfa1*(1/(2*dy))*dQx(Nx,jj);                                                      
end 
end


%----------------- dZx dV/dz ------------------;

for jj=2:1:Ny-1
for kk=2:1:Nz-1                                              
MB(Nx*Ny*Nz+(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*Nz+(jj-1)*Nz+Nz)+   alfa1*(3/(2*dz))*dZx(Nx,jj,Nz);                                                      
end 



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++ The third equation (basic equation#3) ++++++++++; 
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%++++++++++++++ KpE Fzx +++++++++++++++;

%-------------- dZz dU/dz --------------;

for jj=2:1:Ny-1
for kk=2:1:Nz-1                                              
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk-1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk-1)+alfa1*(-1/(2*dz))*dZz(Nx,jj);            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk+1)+ alfa1*(1/(2*dz))*dZz(Nx,jj);                                                      
end 
end

for jj=2:1:Ny-1
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-2)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-2)+ alfa1*(1/(2*dz))*dZz(Nx,jj); 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)+alfa1*(-4/(2*dz))*dZz(Nx,jj);            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)+   alfa1*(3/(2*dz))*dZz(Nx,jj);                                                      
end 



%---------------- dW/dx ----------------;

for jj=2:1:Ny-1
for kk=2:1:Nz                                              
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)+ alfa1*(1/(2*dx));
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)+alfa1*(-4/(2*dx));
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+ alfa1*(3/(2*dx));                                
end 
end 

%-------------- dQx dW/dQ -------------;

for jj=2:1:Ny-1
for kk=2:1:Nz                                              
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz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z); 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz-1)+alfa1*(-4/(2*dz))*dZx(Nx,jj,Nz);            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+Nz)+   alfa1*(3/(2*dz))*dZx(Nx,jj,Nz);                                                      
end 

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++ The end of Basic Boundary Conditions at the terminus +++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;




%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++ Boundary Conditions at the terminus +++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++ The first equation +++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) 1/(2*dx) Kp1 H int (dU/dx)^(Nx-2) -----------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-4)*Ny*Nz+(jj-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-4)*Ny*Nz+(jj-1)*Nz+1)-alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dz/(2*dx);                             
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-4)*Ny*Nz+(jj-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-4)*Ny*Nz+(jj-1)*Nz+2)-alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dz/(2*dx);
 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)+alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dz/(2*dx);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+2)+alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dz/(2*dx);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-4)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-4)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-4)*Ny*Nz+(jj-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-4)*Ny*Nz+(jj-1)*Nz+p)- alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dz/(2*dx); 
end                                            

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-4)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-4)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz/(2*dx);                
end
                                                                           
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)+ alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+p)+ alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dz/(2*dx); 
end                                            

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz/(2*dx);         
end
            
end 




%---------- (2) 1/(2*dx) Kp1 H int ( dQx dU/dq )^(Nx-2) -----------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)-alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);                             
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+2)-alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);
 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+1)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+1)+    alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+2)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+2)+    alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);  
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+1)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+1)+     alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+p)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+p)+     alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy); 
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+kk)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+kk)+    alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                
end
            
end 




%---------- (3) 1/(2*dx) Kp1 H int ( dZx dU/dz )^(Nx-2) ------------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dZx(Nx-2,jj,1) - alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz*d2Zxz(Nx-2,jj,1);

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+2)+ alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dZx(Nx-2,jj,2) - alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz*d2Zxz(Nx-2,jj,2);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dZx(Nx-2,jj,1) - alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz*d2Zxz(Nx-2,jj,1);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+p)- alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dz*d2Zxz(Nx-2,jj,p); 
end                                            

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(1/(2*dx))*Kp1*HIC(Nx-2,jj)*dZx(Nx-2,jj,kk) - alfa2*(1/(2*dx))*Kp1*0.5*HIC(Nx-2,jj)*dz*d2Zxz(Nx-2,jj,kk);                
end
            
end 



%---------- (4) 1/(2*dx) Kp2 H int ( dQy dV/dq )^(Nx-2) -----------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)-alfa2*(1/(2*dx))*Kp2*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);                             
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+2)-alfa2*(1/(2*dx))*Kp2*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);
 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)+    alfa2*(1/(2*dx))*Kp2*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+2)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+2)+    alfa2*(1/(2*dx))*Kp2*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);  
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)+     alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+p)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+p)+     alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy); 
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+kk)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+kk)+    alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                
end
            
end 



%---------- (5) 1/(2*dx) Kp2 H int ( dZy dV/dz )^(Nx-2) ------------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj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Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*dZy(Nx-2,jj,kk) - alfa2*(1/(2*dx))*Kp2*0.5*HIC(Nx-2,jj)*dz*d2Zyz(Nx-2,jj,kk);                
end
            
end 




%---------- (6) 1/(2*dx) Kp2 H int ( dZz dW/dz )^(Nx-2) ------------;


for jj=2:1:Ny-1
                                                      
for kk=2:1:Nz

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*dZz(Nx-2,jj);

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(1/(2*dx))*Kp2*HIC(Nx-2,jj)*dZz(Nx-2,jj);

end
            
end 




%---------- (7) - 4/(2*dx) Kp1 H int (dU/dx)^(Nx-1) -----------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)-alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dz/(2*dx);                             
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+2)-alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dz/(2*dx);
 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)+alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dz/(2*dx);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+2)+alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dz/(2*dx);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+p)- alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dz/(2*dx); 
end                                            

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz/(2*dx);                
end
                                                                           
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)+ alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+p)+ alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dz/(2*dx); 
end                                            

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz/(2*dx);         
end
            
end 




%---------- (8) - 4/(2*dx) Kp1 H int ( dQx dU/dq )^(Nx-1) -----------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)-alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);                             
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-2)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-2)*Nz+2)-alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);
 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+jj*Nz+1)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+jj*Nz+1)+    alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+jj*Nz+2)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+jj*Nz+2)+    alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);  
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+1)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+1)+     alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+p)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+p)+     alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy); 
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+kk)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+kk)+    alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                
end
            
end 




%---------- (9) - 4/(2*dx) Kp1 H int ( dZx dU/dz )^(Nx-1) ------------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dZx(Nx-1,jj,1) - alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz*d2Zxz(Nx-1,jj,1);

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-2)*Ny*Nz+(jj-1)*Nz+2)+ alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dZx(Nx-1,jj,2) - alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz*d2Zxz(Nx-1,jj,2);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dZx(Nx-1,jj,1) - alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz*d2Zxz(Nx-1,jj,1);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+p)- alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dz*d2Zxz(Nx-1,jj,p); 
end                                            

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(-4/(2*dx))*Kp1*HIC(Nx-1,jj)*dZx(Nx-1,jj,kk) - alfa2*(-4/(2*dx))*Kp1*0.5*HIC(Nx-1,jj)*dz*d2Zxz(Nx-1,jj,kk);                
end
            
end 



%---------- (10) - 4/(2*dx) Kp2 H int ( dQy dV/dq )^(Nx-1) -----------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+1)-alfa2*(-4/(2*dx))*Kp2*0.5*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy);                             
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+2)-alfa2*(-4/(2*dx))*Kp2*0.5*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy);
 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)+    alfa2*(-4/(2*dx))*Kp2*0.5*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy);            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+2)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+2)+    alfa2*(-4/(2*dx))*Kp2*0.5*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*0.5*dQy(Nx-1)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy);  
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*0.5*dQy(Nx-1)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)+     alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*0.5*dQy(Nx-1)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+p)=     MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+p)+     alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy); 
end                                            
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+kk)=    MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+kk)+    alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*0.5*dQy(Nx-1)*dz/(2*dy);                
end
            
end 



%---------- (11) - 4/(2*dx) Kp2 H int ( dZy dV/dz )^(Nx-1) ------------;


for jj=2:1:Ny-1

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)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Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*dZy(Nx-1,jj,kk) - alfa2*(-4/(2*dx))*Kp2*0.5*HIC(Nx-1,jj)*dz*d2Zyz(Nx-1,jj,kk);                
end
            
end 




%---------- (12) - 4/(2*dx) Kp2 H int ( dZz dW/dz )^(Nx-1) ------------;



for jj=2:1:Ny-1
                                                      
for kk=2:1:Nz

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*dZz(Nx-1,jj);

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(-4/(2*dx))*Kp2*HIC(Nx-1,jj)*dZz(Nx-1,jj);

end
            
end 



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ + KpE dens Freq^2 U +++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for jj=2:1:Ny-1
    
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(Nx,jj);

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+2) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(Nx,jj);

end 



for jj=2:1:Ny-1
    
for kk=3:1:Nz-1 
MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(Nx,jj);

for p=2:1:kk-1                                                         
 MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+p)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(Nx,jj);  
end

MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(Nx,jj);
end

end 



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++ The second equation +++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) 1/(2*dx) H int ( dQy dU/dq )^(Nx-2) -----------;


for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)-alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-2)*Nz+2)-alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);
 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+1)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+1)+    alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+2)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+jj*Nz+2)+    alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+1)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+1)+     alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+p)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+p)+     alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dQy(Nx-2)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+kk)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+kk)+    alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQy(Nx-2)*dz/(2*dy);                
end
            
end 




%---------- (2) 1/(2*dx) H int ( dZy dU/dz )^(Nx-2) ------------;


for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)=MB(Nx*Ny*Nz+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)+alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dz/(2*dx);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+p)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dz/(2*dx);                
end
                                                                           
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)+ alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(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Nz+1)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)+    alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+2)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+2)+    alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)+     alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+p)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+p)+     alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+kk)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+kk)+    alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                
end
            
end 



%---------- (5) 1/(2*dx) H int ( dZx dV/dz )^(Nx-2) ------------;


for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx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a2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQy(Nx-1)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dQy(Nx-1)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQy(Nx-1)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+1)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+1)+     alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQy(Nx-1)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj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z/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dz/(2*dx);                
end
                                                                           
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1)+ alfa2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)+ alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dz/(2*dx);         
end
            
end 




%---------- (9) - 4/(2*dx) H int ( dQx dV/dq )^(Nx-1) -----------;


for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(Nx-1)*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+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)+     alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+p)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(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nz+jj*Nz+2)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+jj*Nz+2)+alfa2*Kp1*dQy(Nx)*0.5*GpHdQInt3_ij(Nx,jj+1)*dz/dy^2;

end




for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+1)+ alfa2*Kp1*dQy(Nx)*0.5*GpHdQInt3_ij(Nx,jj)*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+p)+ alfa2*Kp1*dQy(Nx)*GpHdQInt3_ij(Nx,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)+alfa2*Kp1*dQy(Nx)*0.5*GpHdQInt3_ij(Nx,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+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y(Nx)*0.5*HIC(Nx,jj-1)*dz*(-3/(4*dy*dx));            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+2)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(-3/(4*dy*dx)); 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+jj*Nz+1)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+jj*Nz+1)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj+1)*dz*(3/(4*dy*dx));                        
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+jj*Nz+2)=    MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+jj*Nz+2)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj+1)*dz*(3/(4*dy*dx));
 
end




for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+1)+ alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(-1/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+p)+ alfa2*Kp2*dQy(Nx)*HIC(Nx,jj-1)*dz*(-1/(4*dy*dx));  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(-1/(4*dy*dx));                
end

for kk=3:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+1)+ alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(1/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+p)+ alfa2*Kp2*dQy(Nx)*HIC(Nx,jj-1)*dz*(1/(4*dy*dx));  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+jj*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(1/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+1)+ alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+p)+ alfa2*Kp2*dQy(Nx)*HIC(Nx,jj-1)*dz*(4/(4*dy*dx)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(4/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+1)+ alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj+1)*dz*(-4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+p)+ alfa2*Kp2*dQy(Nx)*HIC(Nx,jj+1)*dz*(-4/(4*dy*dx)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-2)*Ny*Nz+jj*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj+1)*dz*(-4/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+1)+ alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(-3/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+p)+ alfa2*Kp2*dQy(Nx)*HIC(Nx,jj-1)*dz*(-3/(4*dy*dx)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*(-3/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+1)+ alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj+1)*dz*(3/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+p)+ alfa2*Kp2*dQy(Nx)*HIC(Nx,jj+1)*dz*(3/(4*dy*dx)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj+1)*dz*(3/(4*dy*dx));                
end

end 



%---------- (14) Kp2 dQy d/dq ( H ( int ( dQx dU/dq ) ) -----------;


for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+1)+alfa2*Kp2*dQy(Nx)*0.5*GpHdQInt2_ij(Nx,jj)*dz/dy^2;                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+2)+alfa2*Kp2*dQy(Nx)*0.5*GpHdQInt2_ij(Nx,jj)*dz/dy^2;
 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-1)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= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+p)+ alfa2*Kp2*dQy(Nx)*GpHdQInt2_ij(Nx,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-2)*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*GpHdQInt2_ij(Nx,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+1)- alfa2*Kp2*dQy(Nx)*0.5*(GpHdQInt2_ij(Nx,jj)+GpHdQInt2_ij(Nx,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+p)- alfa2*Kp2*dQy(Nx)*(GpHdQInt2_ij(Nx,jj)+GpHdQInt2_ij(Nx,jj+1))*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*Kp2*dQy(Nx)*0.5*(GpHdQInt2_ij(Nx,jj)+GpHdQInt2_ij(Nx,jj+1))*dz/dy^2;                
end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+1)+ alfa2*Kp2*dQy(Nx)*0.5*GpHdQInt2_ij(Nx,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+p)+ alfa2*Kp2*dQy(Nx)*GpHdQInt2_ij(Nx,jj+1)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-1)*Ny*Nz+jj*Nz+kk)+alfa2*Kp2*dQy(Nx)*0.5*GpHdQInt2_ij(Nx,jj+1)*dz/dy^2;         
end
            
end 



%---------- (15) Kp2 dQy d/dq ( H ( int ( dZx dU/dz ) ) ----------------;


for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,(Nx-1)*Ny*Nz+(jj-2)*Nz+1)+alfa2*Kp2*dQy(Nx)*HIC(Nx,jj-1)*dZx(Nx,jj-1,1)/(2*dy) + alfa2*Kp2*dQy(Nx)*0.5*HIC(Nx,jj-1)*dz*d2Zxz(Nx,jj-1,1)/(2*dy);                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*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2*dz*HIC(Nx,jj);

for p=2:1:kk-1                                                         
 MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(Nx,jj);  
end

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(Nx,jj);
end

end 



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++++ The third equation ++++++++++++++++++++++++; 
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) 1/(2*dx) H int ( dZz dU/dz )^(Nx-2) ------------;


for jj=2:1:Ny-1
                                                      
for kk=2:1:Nz

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dZz(Nx-2,jj);

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)+alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dZz(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Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+p)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dz/(2*dx);                
end
                                                                           
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)+ alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz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ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)+    alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+2)=    MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+2)+    alfa2*(1/(2*dx))*0.5*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy);  
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+1)+     alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+p)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+p)+     alfa2*(1/(2*dx))*HIC(Nx-2,jj)*dQx(Nx-2,jj)*dz/(2*dy); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+kk)=    MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+jj*Nz+kk)+    alfa2*(1/(2*dx))*HIC(Nx-2,jj)*0.5*dQx(Nx-2,jj)*dz/(2*dy);                
end
            
end 



%---------- (4) 1/(2*dx) H int ( dZx dW/dz )^(Nx-2) ------------;


for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*N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+(Nx-3)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+p)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dz/(2*dx);                
end
                                                                           
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1)+ alfa2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)+ alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)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nx-2)*Ny*Nz+jj*Nz+2)+    alfa2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);

end



for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+1)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+p)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy);  
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-2)*Nz+kk)-alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                
end


for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+1)+     alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+p)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+p)+     alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dQx(Nx-1,jj)*dz/(2*dy); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+kk)=    MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+jj*Nz+kk)+    alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*0.5*dQx(Nx-1,jj)*dz/(2*dy);                
end
            
end 



%---------- (8) - 4/(2*dx) H int ( dZx dW/dz )^(Nx-1) ------------;


for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+1)- alfa2*(-4/(2*dx))*HIC(Nx-1,jj)*dZx(Nx-1,jj,1) - alfa2*(-4/(2*dx))*0.5*HIC(Nx-1,jj)*dz*d2Zxz(Nx-1,jj,1);

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(jj-1)*Nz+2)=MB(2*Nx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HdQInt3_ij(Nx,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1)-alfa2*dQy(Nx)*0.5*(GpHdQInt3_ij(Nx,jj)+GpHdQInt3_ij(Nx,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)-alfa2*dQy(Nx)*(GpHdQInt3_ij(Nx,jj)+GpHdQInt3_ij(Nx,jj+1))*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)-alfa2*dQy(Nx)*0.5*(GpHdQInt3_ij(Nx,jj)+GpHdQInt3_ij(Nx,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+jj*Nz+1)+alfa2*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nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(Nx,jj);

for p=2:1:kk-1                                                         
 MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(Nx,jj);  
end

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(jj-1)*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(Nx,jj);
end

end 


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++ The end of Boundary Conditions at the terminus +++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;



%++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++ The lateral edge Y=Y1 (Jy=1) +++++++++++;
%++++++++++++++ (free lateral edge) +++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++ Basic Boundary Conditions at the lateral edge Y=Y1 ++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++ The first equation (basic equation #1) ++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++ KpE Fxx nx ++++++++++++++++++;

%----------------- Kp1 dU/dx Y1x -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)+alfa1*Kp1*(-1/(2*dx))*difY1(ii);
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=    MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+    alfa1*Kp1*(1/(2*dx))*difY1(ii);                                          
end 
end


%-------- i=Nx ------;

for kk=2:1:Nz 
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+ alfa1*Kp1*(1/(2*dx))*difY1(ii); 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa1*Kp1*(-4/(2*dx))*difY1(ii); 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+ alfa1*Kp1*(3/(2*dx))*difY1(ii); 
end


%----------------- Kp1 dQx dU/dQ --------------;

for ii=2:1:Nx 
for kk=2:1:Nz 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+     alfa1*Kp1*dQx(ii,1)*(-3/(2*dy))*difY1(ii); 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+   alfa1*Kp1*dQx(ii,1)*(4/(2*dy))*difY1(ii); 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa1*Kp1*dQx(ii,1)*(-1/(2*dy))*difY1(ii); 
end 
end


%--------------- Kp1 dZx dU/dz Y1x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)+alfa1*Kp1*(-1/(2*dz))*dZx(ii,1,kk)*difY1(ii);
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)+ alfa1*Kp1*(1/(2*dz))*dZx(ii,1,kk)*difY1(ii);                                                          
end 
end

for ii=2:1:Nx
MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)=MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)+ alfa1*Kp1*(1/(2*dz))*dZx(ii,1,Nz)*difY1(ii);
MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)=MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)+alfa1*Kp1*(-4/(2*dz))*dZx(ii,1,Nz)*difY1(ii);
MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)=  MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)+   alfa1*Kp1*(3/(2*dz))*dZx(ii,1,Nz)*difY1(ii);
end 


%--------------- Kp2 dQy dV/dQ Y1x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+     alfa1*Kp2*(-3/(2*dy))*dQy(ii)*difY1(ii);
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)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end 



%--------------- Kp2 dZz dW/dz Y1x ----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)=MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)+alfa1*Kp2*(-1/(2*dz))*dZz(ii,1)*difY1(ii);
MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1)=MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1)+alfa1*Kp2*(1/(2*dz))*dZz(ii,1)*difY1(ii);                                                          
end 
end

for ii=2:1:Nx
MB((ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-2)=MB((ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-2)+ alfa1*Kp2*(1/(2*dz))*dZz(ii,1)*difY1(ii);
MB((ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)=MB((ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)+alfa1*Kp2*(-4/(2*dz))*dZz(ii,1)*difY1(ii);
MB((ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)=  MB((ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)+   alfa1*Kp2*(3/(2*dz))*dZz(ii,1)*difY1(ii);
end 



%++++++++++++++++ KpE Fxy ny +++++++++++++++++;


%--------------- - dQy dU/dQ -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)-     alfa1*(-3/(2*dy))*dQy(ii);
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)-   alfa1*(4/(2*dy))*dQy(ii);
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)-alfa1*(-1/(2*dy))*dQy(ii);

end 
end

%--------------- - dZy dU/dz -----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)-alfa1*(-1/(2*dz))*dZy(ii,1,kk);
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)- alfa1*(1/(2*dz))*dZy(ii,1,kk);                                                          
end 
end

for ii=2:1:Nx
MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)=MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)- alfa1*(1/(2*dz))*dZy(ii,1,Nz);
MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)=MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)-alfa1*(-4/(2*dz))*dZy(ii,1,Nz);
MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)=  MB((ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)-   alfa1*(3/(2*dz))*dZy(ii,1,Nz);
end 


%----------------- - dV/dx -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa1*(-1/(2*dx));
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)=    MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)    - alfa1*(1/(2*dx));                                          
end 
end

%-------- i=Nx ------;

for kk=2:1:Nz                                              
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)- alfa1*(1/(2*dx));
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)-alfa1*(-4/(2*dx));
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)- alfa1*(3/(2*dx));
end 


%--------------- - dQx dV/dQ -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)-     alfa1*(-3/(2*dy))*dQx(ii,1);
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)-   alfa1*(4/(2*dy))*dQx(ii,1);
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)-alfa1*(-1/(2*dy))*dQx(ii,1);
end 
end


%--------------- - dZx dV/dz -----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)-alfa1*(-1/(2*dz))*dZx(ii,1,kk);
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1)- alfa1*(1/(2*dz))*dZx(ii,1,kk);                                                          
end 
end

for ii=2:1:Nx
MB((ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-2)=MB((ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-2)- alfa1*(1/(2*dz))*dZx(ii,1,Nz);
MB((ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)=MB((ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)-alfa1*(-4/(2*dz))*dZx(ii,1,Nz);
MB((ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)=  MB((ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)-   alfa1*(3/(2*dz))*dZx(ii,1,Nz);
end 



%++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++ The second equation (basic equation #2) +++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++ KpE Fyx nx +++++++++++++++++++;


%--------------- dQy dU/dQ Y1x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+     alfa1*(-3/(2*dy))*dQy(ii)*difY1(ii);
MB(Nx*Ny*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)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)+   alfa1*(3/(2*dz))*dZy(ii,1,Nz)*difY1(ii);
end 



%----------------- dV/dx Y1x -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)+alfa1*(-1/(2*dx))*difY1(ii);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)+     alfa1*(1/(2*dx))*difY1(ii);                                          
end 
end

%------ i=Nx -------;

for kk=2:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+ alfa1*(1/(2*dx))*difY1(Nx);    
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa1*(-4/(2*dx))*difY1(Nx);
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+ alfa1*(3/(2*dx))*difY1(Nx);                                          
end 

%--------------- dQx dV/dQ Y1x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*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*(1/(2*dz))*dZx(ii,1,Nz)*difY1(ii);    
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)+alfa1*(-4/(2*dz))*dZx(ii,1,Nz)*difY1(ii);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)+   alfa1*(3/(2*dz))*dZx(ii,1,Nz)*difY1(ii);                                                          
end 



%+++++++++++++++++ KpE Fyy ny +++++++++++++++++;


%--------------- - Kp1 dQy dV/dQ -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk) -    alfa1*Kp1*(-3/(2*dy))*dQy(ii);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)-   alfa1*Kp1*(4/(2*dy))*dQy(ii);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)-alfa1*Kp1*(-1/(2*dy))*dQy(ii);
end 
end

%--------------- - Kp1 dZy dV/dz ----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
M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dy))*dQx(ii,1);
end 
end

%--------------- - Kp2 dZx dU/dz -----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)-alfa1*Kp2*(-1/(2*dz))*dZx(ii,1,kk);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)- alfa1*Kp2*(1/(2*dz))*dZx(ii,1,kk);                                                          
end
end

for ii=2:1:Nx
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)- alfa1*Kp2*(1/(2*dz))*dZx(ii,1,Nz);    
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)-alfa1*Kp2*(-4/(2*dz))*dZx(ii,1,Nz);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)-   alfa1*Kp2*(3/(2*dz))*dZx(ii,1,Nz);                                                          
end 



%--------------- - Kp2 dZz dW/dz ----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)-alfa1*Kp2*(-1/(2*dz))*dZz(ii,1);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1) -alfa1*Kp2*(1/(2*dz))*dZz(ii,1);                                                          
end 
end

for ii=2:1:Nx
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-2)- alfa1*Kp2*(1/(2*dz))*dZz(ii,1);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)-alfa1*Kp2*(-4/(2*dz))*dZz(ii,1);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz) -  alfa1*Kp2*(3/(2*dz))*dZz(ii,1);                                                          
end 



%+++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++ The third equation (basic equation #3) ++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++;

%+++++++++++++++++ KpE Fzx nx ++++++++++++++++++;

%--------------- dZz dU/dz Y1x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk-1)+alfa1*(-1/(2*dz))*dZz(ii,1)*difY1(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk+1)+ alfa1*(1/(2*dz))*dZz(ii,1)*difY1(ii);                                                          
end 
end

for ii=2:1:Nx
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-2)+ alfa1*(1/(2*dz))*dZz(ii,1)*difY1(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz-1)+alfa1*(-4/(2*dz))*dZz(ii,1)*difY1(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,(ii-1)*Ny*Nz+Nz)+   alfa1*(3/(2*dz))*dZz(ii,1)*difY1(ii);                                                          
end 



%----------------- dW/dx Y1x -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)+alfa1*(-1/(2*dx))*difY1(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)+     alfa1*(1/(2*dx))*difY1(ii);                                          
end 
end

%-------- i=Nx ---------;

for kk=2:1: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,Nz)*difY1(ii);                                                          
end 



%++++++++++++++++ KpE Fzy ny +++++++++++++++++;


%--------------- - dZz dV/dz ----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk-1)-alfa1*(-1/(2*dz))*dZz(ii,1);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk+1)- alfa1*(1/(2*dz))*dZz(ii,1);                                                          
end 
end

for ii=2:1:Nx
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-2)- alfa1*(1/(2*dz))*dZz(ii,1);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)-alfa1*(-4/(2*dz))*dZz(ii,1);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)-   alfa1*(3/(2*dz))*dZz(ii,1);                                                          
end 



%--------------- - dQy dW/dQ -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz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-2)- alfa1*(1/(2*dz))*dZy(ii,1,Nz);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz-1)-alfa1*(-4/(2*dz))*dZy(ii,1,Nz);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)-   alfa1*(3/(2*dz))*dZy(ii,1,Nz);                                                          
end 


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++ The end of Basic Boundary Conditions at the lateral edge Y=Y1 +++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++ Boundary Conditions at the lateral edge Y=Y1 ++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

%+++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++ The first equation +++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++;


%------------- (1) Kp1 d/dx ( H ( int (dU/dx) ) ----------------;

%--------------- (1,a) Kp1 dH/dx int (dU/dx)  -----------------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)-alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);                             
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)-alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);

MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)+alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);            
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)-  alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)-  alfa2*Kp1*dHx(ii,1)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)-alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+  alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+  alfa2*Kp1*dHx(ii,1)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+alfa2*Kp1*0.5*dHx(ii,1)*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(1/(2*dx));                             
MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(1/(2*dx));
 
MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+1)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(-4/(2*dx));            
MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+2)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(-4/(2*dx));

MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+1)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(3/(2*dx));            
MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(3/(2*dx));



for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+ alfa2*Kp1*0.5*dHx(Nx,1)*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+ alfa2*Kp1*dHx(Nx,1)*dz*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+ alfa2*Kp1*0.5*dHx(Nx,1)*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+ alfa2*Kp1*dHx(Nx,1)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+ alfa2*Kp1*0.5*dHx(Nx,1)*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+ alfa2*Kp1*dHx(Nx,1)*dz*(3/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*Kp1*0.5*dHx(Nx,1)*dz*(3/(2*dx));         
end




%--------------- (1,b) Kp1 H d/dx ( int (dU/dx) ) -----------------;



for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)+alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;                             
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)+alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;
 
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*Kp1*HIC(ii,1)*dz/dx^2;            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)-alfa2*Kp1*HIC(ii,1)*dz/dx^2;

MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)+alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;            
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)+ alfa2*Kp1*HIC(ii,1)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*Kp1*HIC(ii,1)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)- alfa2*Kp1*HIC(ii,1)*dz*2/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)-alfa2*Kp1*HIC(ii,1)*dz/dx^2;                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+ alfa2*Kp1*HIC(ii,1)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,1)*dz/dx^2;         
end
            
end 


%------- i=Nx ------;


MB((Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-1/dx^2);                             
MB((Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-1/dx^2);

MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(4/dx^2);                             
MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(4/dx^2);
 
MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-5/dx^2);            
MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-5/dx^2);

MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(2/dx^2);            
MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(2/dx^2);



for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-1/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*dz*(-1/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-1/dx^2);                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*dz*(4/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*dz*(4/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(4/dx^2);                

end
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-5/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*dz*(-5/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(-5/dx^2);         
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*dz*(2/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*dz*(2/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*dz*(2/dx^2);         
end




%---------- (2) Kp1 d/dx ( H ( int ( dQx dU/dq ) ) --------------;

%---------- (2,a) Kp1 d/dx ( H dQx ) int ( dU/dq ) --------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)+     alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-3/(2*dy));                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-3/(2*dy));

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(4/(2*dy));                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(4/(2*dy));
 
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-1/(2*dy));            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)+     alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)+     alfa2*Kp1*d2QxHx(ii,1)*dz*(-3/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+    alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)+  alfa2*Kp1*d2QxHx(ii,1)*dz*(4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+ alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*d2QxHx(ii,1)*dz*(-1/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*d2QxHx(ii,1)*dz*(-1/(2*dy));                
end
            
end 



%---------- (2,b) Kp1 H dQx d/dx ( int ( dU/dq ) ) -------------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));                             
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)+     alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));
 
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy));            
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+2)+  alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy));

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2*Nz+1)+alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy));            
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2*Nz+2)+alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy));

 
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy));                        
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+     alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy));

MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy));                        
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+2)+  alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy));

MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+1)+alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy));                        
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+2)+alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)+      alfa2*Kp1*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));  
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+      alfa2*Kp1*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(ii,1)*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*Nz+2,(Nx-1)*Ny*Nz+2)+     alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-9/(4*dx*dy));

MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+Nz+1)=  MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                        
MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+Nz+2)=  MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+Nz+2)+  alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));

MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                        
MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));




for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+      alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));  
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(-1/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+      alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(-16/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-9/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+      alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(-9/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-9/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                
end




%---------- (3) Kp1 d/dx ( H ( int ( dZx dU/dz ) ) ----------------;

%------------ (3,a) Kp1 dH/dx int ( dZx dU/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*Kp1*dHx(ii,1)*dZx(ii,1,1) - alfa2*Kp1*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,1);                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*Kp1*dHx(ii,1)*dZx(ii,1,2) - alfa2*Kp1*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*Kp1*dHx(ii,1)*dZx(ii,1,1) - alfa2*Kp1*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)- alfa2*Kp1*dHx(ii,1)*dz*d2Zxz(ii,1,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+alfa2*Kp1*dHx(ii,1)*dZx(ii,1,kk) - alfa2*Kp1*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,kk);                
end

end



%------------ (3,b) Kp1 H d/dx ( int ( dZx dU/dz ) ) --------------;


for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)+alfa2*Kp1*HIC(ii,1)*dZx(ii-1,1,1)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*dz*d2Zxz(ii-1,1,1)/(2*dx);                             
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)-alfa2*Kp1*HIC(ii,1)*dZx(ii-1,1,2)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*dz*d2Zxz(ii-1,1,2)/(2*dx);

MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)-    alfa2*Kp1*HIC(ii,1)*dZx(ii+1,1,1)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,1)*dz*d2Zxz(ii+1,1,1)/(2*dx);            
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+    alfa2*Kp1*HIC(ii,1)*dZx(ii+1,1,2)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,1)*dz*d2Zxz(ii+1,1,2)/(2*dx);

end



for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)+ alfa2*Kp1*HIC(ii,1)*dZx(ii-1,1,1)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*dz*d2Zxz(ii-1,1,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)+ alfa2*Kp1*HIC(ii,1)*dz*d2Zxz(ii-1,1,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)-alfa2*Kp1*HIC(ii,1)*dZx(ii-1,1,kk)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*dz*d2Zxz(ii-1,1,kk)/(2*dx);                
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)- alfa2*Kp1*HIC(ii,1)*dZx(ii+1,1,1)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,1)*dz*d2Zxz(ii+1,1,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=     MB((ii-1)*Ny*Nz+kk,ii*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x-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+1)-alfa2*Kp1*HIC(Nx,1)*dZx(Nx,1,1)*(3/(2*dx)) -    alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx,1,1)*(3/(2*dx));            
MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)+alfa2*Kp1*HIC(Nx,1)*dZx(Nx,1,2)*(3/(2*dx)) -    alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx,1,2)*(3/(2*dx));



for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)- alfa2*Kp1*HIC(Nx,1)*dZx(Nx-2,1,1)*(1/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx-2,1,1)*(1/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)- alfa2*Kp1*HIC(Nx,1)*dz*d2Zxz(Nx-2,1,p)*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*dZx(Nx-2,1,kk)*(1/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx-2,1,kk)*(1/(2*dx));                
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)- alfa2*Kp1*HIC(Nx,1)*dZx(Nx-1,1,1)*(-4/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx-1,1,1)*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)- alfa2*Kp1*HIC(Nx,1)*dz*d2Zxz(Nx-1,1,p)*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*dZx(Nx-1,1,kk)*(-4/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx-1,1,kk)*(-4/(2*dx));         
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)- alfa2*Kp1*HIC(Nx,1)*dZx(Nx,1,1)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx,1,1)*(3/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)- alfa2*Kp1*HIC(Nx,1)*dz*d2Zxz(Nx,1,p)*(3/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*dZx(Nx,1,kk)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*dz*d2Zxz(Nx,1,kk)*(3/(2*dx));         
end




%---------- (4) Kp2 d/dx ( H ( int ( dQy dV/dq ) ) --------------;

%---------- (4,a) Kp2 d/dx ( H dQy ) int ( dV/dq ) --------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx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1)*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+     alfa2*Kp2*d2QyHx(ii,1)*dz*(-3/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*Kp2*0.5*d2QyHx(ii,1)*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp2*0.5*d2QyHx(ii,1)*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+  alfa2*Kp2*d2QyHx(ii,1)*dz*(4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+ alfa2*Kp2*0.5*d2QyHx(ii,1)*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*d2QyHx(ii,1)*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*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*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)=    MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)+alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(-1/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)+      alfa2*Kp2*HIC(ii,1)*dQy(ii)*dz*(3/(4*dx*dy));  
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(ii,1)*dQy(ii)*dz*(-4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(ii,1)*dQy(ii)*dz*(1/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)+      alfa2*Kp2*HIC(ii,1)*dQy(ii)*dz*(-3/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(-3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(ii,1)*dQy(ii)*dz*(4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,1)*dQy(ii)*dz*(-1/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(ii,1)*dQy(ii)*dz*(-1/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)=MB((ii-1)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)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)+      alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(-3/(4*dx*dy));  
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(4/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(-1/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(12/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+      alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(12/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(-16/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(4/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(4/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-9/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)+      alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(-9/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-9/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(Nx,1)*dQy(Nx)*dz*(-3/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,1)*dQy(Nx)*dz*(-3/(4*dx*dy));                
end




%---------- (5) Kp2 d/dx ( H ( int ( dZy dV/dz ) ) ----------------;

%------------ (5,a) Kp2 dH/dx  int ( dZy dV/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*Kp2*dHx(ii,1)*dZy(ii,1,1) - alfa2*Kp2*0.5*dHx(ii,1)*dz*d2Zyz(ii,1,1);                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*Kp2*dHx(ii,1)*dZy(ii,1,2) - alfa2*Kp2*0.5*dHx(ii,1)*dz*d2Zyz(ii,1,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*Kp2*dHx(ii,1)*dZy(ii,1,1) - alfa2*Kp2*0.5*dHx(ii,1)*dz*d2Zyz(ii,1,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*Kp2*dHx(ii,1)*dz*d2Zyz(ii,1,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*Kp2*dHx(ii,1)*dZy(ii,1,kk) - alfa2*Kp2*0.5*dHx(ii,1)*dz*d2Zyz(ii,1,kk);                
end

end



%------------ (5,b) Kp2 H d/dx ( int ( dZy dV/dz ) ---------------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+alfa2*Kp2*HIC(ii,1)*dZy(ii-1,1,1)/(2*dx) + alfa2*Kp2*0.5*HIC(ii,1)*dz*d2Zyz(ii-1,1,1)/(2*dx);                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+2)-alfa2*Kp2*HIC(ii,1)*dZy(ii-1,1,2)/(2*dx) + alfa2*Kp2*0.5*HIC(ii,1)*dz*d2Zyz(ii-1,1,2)/(2*dx);

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+1)=    MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+1)-    alfa2*Kp2*HIC(ii,1)*dZy(ii+1,1,1)/(2*dx) - alfa2*Kp2*0.5*HIC(ii,1)*dz*d2Zyz(ii+1,1,1)/(2*dx);            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2)=    MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2)+    alfa2*Kp2*HIC(ii,1)*dZy(ii+1,1,2)/(2*dx) - alfa2*Kp2*0.5*HIC(ii,1)*dz*d2Zyz(ii+1,1,2)/(2*dx);

end



for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+ alfa2*Kp2*HIC(ii,1)*dZy(ii-1,1,1)/(2*dx) + alfa2*Kp2*0.5*HIC(ii,1)*dz*d2Zyz(ii-1,1,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)+ alfa2*Kp2*HIC(ii,1)*dz*d2Zyz(ii-1,1,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa2*Kp2*HIC(ii,1)*dZy(ii-1,1,kk)/(2*dx) + alfa2*Kp2*0.5*HIC(ii,1)*dz*d2Zyz(ii-1,1,kk)/(2*dx);                
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)=     MB((ii-1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Ny*Nz+(Nx-3)*Ny*Nz+p)- alfa2*Kp2*HIC(Nx,1)*dz*d2Zyz(Nx-2,1,p)*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+alfa2*Kp2*HIC(Nx,1)*dZy(Nx-2,1,kk)*(1/(2*dx)) - alfa2*Kp2*0.5*HIC(Nx,1)*dz*d2Zyz(Nx-2,1,kk)*(1/(2*dx));                
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)- alfa2*Kp2*HIC(Nx,1)*dZy(Nx-1,1,1)*(-4/(2*dx)) - alfa2*Kp2*0.5*HIC(Nx,1)*dz*d2Zyz(Nx-1,1,1)*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)- alfa2*Kp2*HIC(Nx,1)*dz*d2Zyz(Nx-1,1,p)*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa2*Kp2*HIC(Nx,1)*dZy(Nx-1,1,kk)*(-4/(2*dx)) - alfa2*Kp2*0.5*HIC(Nx,1)*dz*d2Zyz(Nx-1,1,kk)*(-4/(2*dx));         
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)- alfa2*Kp2*HIC(Nx,1)*dZy(Nx,1,1)*(3/(2*dx)) - alfa2*Kp2*0.5*HIC(Nx,1)*dz*d2Zyz(Nx,1,1)*(3/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)- alfa2*Kp2*HIC(Nx,1)*dz*d2Zyz(Nx,1,p)*(3/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+alfa2*Kp2*HIC(Nx,1)*dZy(Nx,1,kk)*(3/(2*dx)) - alfa2*Kp2*0.5*HIC(Nx,1)*dz*d2Zyz(Nx,1,kk)*(3/(2*dx));         
end




%---------- (6) Kp2 d/dx ( H ( int ( dZz dW/dz ) ) ----------------;

%----------- (6,a) Kp2 dH/dx ( int ( dZz dW/dz ) ) ----------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*Kp2*dHx(ii,1)*dZz(ii,1);                             
MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*Kp2*dHx(ii,1)*dZz(ii,1);

end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*Kp2*dHx(ii,1)*dZz(ii,1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Zz(Nx,1)*(3/(2*dx));

MB((Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+alfa2*Kp2*HIC(Nx,1)*dZz(Nx,1)*(3/(2*dx));

end



%---------- (7) Kp1 dQx d/dq ( H ( int ( dU/dx ) ) ----------------;

%------------- (7,a) Kp1 dQx dH/dq  int ( dU/dx ) ----------------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)-alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                             
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)-alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);

MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)+    alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);            
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+    alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx); 

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)- alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)- alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*dz/(2*dx);  
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)-alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+     alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=     MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+     alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*dz/(2*dx); 
end                                            
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=    MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+    alfa2*Kp1*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                
end

end 


%------- i=Nx ------;

MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(1/(2*dx));                             
MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(1/(2*dx));

MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+1)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(-4/(2*dx));            
MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-2)*Ny*Nz+2)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(-4/(2*dx));

MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+1)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(3/(2*dx));            
MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(3/(2*dx));


for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+ alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(1/(2*dx));                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+ alfa2*Kp1*dQx(Nx,1)*d1Hq(Nx,1)*dz*(1/(2*dx));  
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(1/(2*dx));                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+ alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(-4/(2*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+ alfa2*Kp1*dQx(Nx,1)*d1Hq(Nx,1)*dz*(-4/(2*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(-4/(2*dx));                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+ alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(3/(2*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+ alfa2*Kp1*dQx(Nx,1)*d1Hq(Nx,1)*dz*(3/(2*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*Kp1*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(3/(2*dx));                
end



%----------- (7,b) Kp1 dQx H d/dq ( int ( dU/dx ) ) --------------;


for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)+     alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));                             
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)+     alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+1)+  alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-4/(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,1)*dz*(-1/(4*dy*dx));            
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+2)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+2)+    alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-1/(4*dy*dx));

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)+      alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)+      alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*(3/(4*dy*dx));  
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)+     alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)+   alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)+   alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*(-4/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(1/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*(1/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(1/(4*dy*dx));                
end


for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+      alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-3/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+      alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*(-3/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+     alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-3/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)+   alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(4/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)+   alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*(4/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)+ alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-1/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)+ alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*(-1/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-1/(4*dy*dx));                
end
            
end 



%------ i=Nx ------;


MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=     MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)+     alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));                             
MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)=     MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)+     alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));

MB((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Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));            
MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)=MB((Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));



for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+      alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+      alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(-3/(4*dy*dx));  
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+     alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+1)+   alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+p)+   alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(4/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-1/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(-1/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-1/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+      alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+      alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(12/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+     alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)+   alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-16/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)+   alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(-16/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-16/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(4/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)=      MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+      alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-9/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)=      MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+      alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(-9/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=     MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+     alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-9/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)=   MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)+   alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)=   MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)+   alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(12/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)=  MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*dQx(Nx,1)*HIC(Nx,1)*dz*(-3/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));                
end




%---------- (8) Kp1 dQx d/dq ( H ( int ( dQx dU/dq ) ) --------------;

%----------- (8,a) Kp1 dQx d(H dQx)/dq  int ( dU/dq ) --------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)+     alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-3/(2*dy));                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-3/(2*dy));
 
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(4/(2*dy));            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(4/(2*dy));

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-1/(2*dy));            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-1/(2*dy));

end


for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)+      alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-3/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)+      alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*dz*(-3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+     alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-3/(2*dy));                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)+   alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(4/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)+   alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*dz*(4/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(4/(2*dy));                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-1/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*dz*(-1/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-1/(2*dy));         
end
            
end 




%----------- (8,b) Kp1 dQx^2 H d/dq ( int ( dU/dq ) ) -------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)+     alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(2/dy^2);                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(2/dy^2);
 
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-5/dy^2);            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-5/dy^2);

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(4/dy^2);            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(4/dy^2);

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+1)+alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-1/dy^2);            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+2)+alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-1/dy^2);

end



for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)+     alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(2/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)+     alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*dz*(2/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+    alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(2/dy^2);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)+   alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-5/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)+   alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*dz*(-5/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-5/dy^2);                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(4/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*dz*(4/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(4/dy^2);         
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-1/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*dz*(-1/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)+alfa2*Kp1*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-1/dy^2);         
end

            
end 



%---------- (9) Kp1 dQx d/dq ( H ( int ( dZx dU/dz ) ) ---------------;

%------------ (9,a) Kp1 dQx dH/dq  int ( dZx dU/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*dZx(ii,1,1) - alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zxz(ii,1,1);            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*dZx(ii,1,2) - alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zxz(ii,1,2);

end


for ii=2:1:Nx

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*dZx(ii,1,1) - alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)- alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*dz*d2Zxz(ii,1,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*dZx(ii,1,kk) - alfa2*Kp1*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zxz(ii,1,kk);         
end
            
end 



%---------- (9,b) Kp1 dQx H d/dq ( int ( dZx dU/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-     alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,1,1)*(-3/(2*dy)) - alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,1,1)*(-3/(2*dy));                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,1,2)*(-3/(2*dy)) - alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,1,2)*(-3/(2*dy));

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)-  alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,2,1)*(4/(2*dy)) -  alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,2,1)*(4/(2*dy));            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,2,2)*(4/(2*dy)) -  alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,2,2)*(4/(2*dy));

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)-alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,3,1)*(-1/(2*dy)) - alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,3,1)*(-1/(2*dy));            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,3,2)*(-1/(2*dy)) - alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,3,2)*(-1/(2*dy));

end



for ii=2:1:Nx

    
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)-      alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,1,1)*(-3/(2*dy)) - alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zxz(ii,1,1)*(-3/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)-      alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*d2Zxz(ii,1,p)*(-3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+     alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,1,kk)*(-3/(2*dy)) - alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zxz(ii,1,kk)*(-3/(2*dy));                
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)-   alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,2,1)*(4/(2*dy)) - alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zxz(ii,2,1)*(4/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)-   alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*d2Zxz(ii,2,p)*(4/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+  alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,2,kk)*(4/(2*dy)) - alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zxz(ii,2,kk)*(4/(2*dy));         
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)- alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,3,1)*(-1/(2*dy)) - alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,3,1)*(-1/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)- alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dz*d2Zxz(ii,3,p)*(-1/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*dQx(ii,1)*HIC(ii,1)*dZx(ii,3,kk)*(-1/(2*dy)) - alfa2*Kp1*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,3,kk)*(-1/(2*dy));         
end


end 




%---------- (10) Kp2 dQx d/dq ( H ( int ( dQy dV/dq ) ) --------------;

%----------- (10,a) Kp2 dQx d(dQy H)/dq  int ( dV/dq ) --------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-3/(2*dy));                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+     alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-3/(2*dy));
 
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(4/(2*dy));            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+2)+  alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(4/(2*dy));

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-1/(2*dy));            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-1/(2*dy));

end



for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+      alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-3/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+      alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*dz*(-3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=    MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+     alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-3/(2*dy));                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+   alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(4/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+   alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*dz*(4/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+  alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(4/(2*dy));                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-1/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*dz*(-1/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*dQx(ii,1)*d2QyHq(ii,1)*0.5*dz*(-1/(2*dy));         
end
            
end 



%---------- (10,b) Kp2 dQx H dQy  d/dq ( int (  dV/dq ) ) -------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(2/dy^2);                             
MB((ii-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2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+2)+alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(-1/dy^2);

end



for ii=2:1:Nx

    
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+      alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(2/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+      alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*dz*(2/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+     alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(2/dy^2);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+   alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(-5/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+   alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*dz*(-5/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+  alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(-5/dy^2);                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(4/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*dz*(4/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(4/dy^2);         
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(-1/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*dz*(-1/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+kk)+alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dQy(ii)*0.5*dz*(-1/dy^2);         
end

            
end 




%---------- (11) Kp2 dQx d/dq ( H ( int ( dZy dV/dz ) ) ----------------;

%------------ (11,a) Kp2 dQx dH/dq  int ( dZy dV/dz ) ----------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*dZy(ii,1,1) - alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zyz(ii,1,1);            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*dZy(ii,1,2) - alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zyz(ii,1,2);

end



for ii=2:1:Nx
                                                      

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*dZy(ii,1,1) - alfa2*Kp2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz*d2Zyz(ii,1,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*dz*d2Zyz(ii,1,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*dZy(ii,1,kk) - alfa2*Kp2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz*d2Zyz(ii,1,kk);         
end
            
end 


%---------- (11,b) Kp2 dQx H  d/dq ( int ( dZy dV/dz ) ) ---------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-     alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,1,1)*(-3/(2*dy)) - alfa2*Kp2*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zyz(ii,1,1)*(-3/(2*dy));                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+     alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,1,2)*(-3/(2*dy)) - alfa2*Kp2*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zyz(ii,1,2)*(-3/(2*dy));

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-  alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,2,1)*(4/(2*dy)) -  alfa2*Kp2*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zyz(ii,2,1)*(4/(2*dy));            
MB((ii-1)*Ny*Nz+2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+p)-      alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dz*d2Zyz(ii,1,p)*(-3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+     alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,1,kk)*(-3/(2*dy)) - alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zyz(ii,1,kk)*(-3/(2*dy));                
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-   alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,2,1)*(4/(2*dy)) - alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zyz(ii,2,1)*(4/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)-   alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dz*d2Zyz(ii,2,p)*(4/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+  alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,2,kk)*(4/(2*dy)) - alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zyz(ii,2,kk)*(4/(2*dy));         
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)- alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,3,1)*(-1/(2*dy)) - alfa2*Kp2*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zyz(ii,3,1)*(-1/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)- alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dz*d2Zyz(ii,3,p)*(-1/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZy(ii,3,kk)*(-1/(2*dy)) - alfa2*Kp2*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zyz(ii,3,kk)*(-1/(2*dy));         
end

end 




%---------- (12) Kp2 dQx d/dq ( H ( int ( dZz dW/dz ) ) ----------------;

%------------- (12,a) Kp2 dQx dH/dq  int ( dZz dW/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*dZz(ii,1);            
MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*Kp2*dQx(ii,1)*d1Hq(ii,1)*dZz(ii,1);

end


for ii=2:1:Nx

for kk=3:1:Nz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ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)- alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZz(ii,3)*(-1/(2*dy));

MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*dQx(ii,1)*HIC(ii,1)*dZz(ii,3)*(-1/(2*dy));

end
            
end 




%--------- (13) (-3/(2*dy)) Kp1 ( dQy H dY1/dx int (dU/dx) )^1  ----------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)-alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);                             
MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)-alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+1)+    alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);            
MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB((ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+    alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)- alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)- alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)-alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)+alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(1/(2*dx));                             
MB((Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)=MB((Nx-1)*Ny*Nz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,(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz-1                 

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)= MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*dz*(3/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(3/(2*dx));         
end




%------- (14) (-3/(2*dy)) Kp1 ( dQy H dY1/dx int ( dQx dU/dq ) )^1 -------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));
 
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)+     alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-3/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+    alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)+  alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+ alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));                
end
            
end 




%-------- (15) (-3/(2*dy)) Kp1 ( dQy H dY1/dx int ( dZx dU/dz ) )^1 ------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dZx(ii,1,1) - alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,1);                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dZx(ii,1,2) - alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dZx(ii,1,1) - alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)- alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii,1,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*dZx(ii,1,kk) - alfa2*(-3/(2*dy))*Kp1*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,kk);                
end

end




%------- (16) (-3/(2*dy)) Kp2 ( dQy H dY1/dx int ( dQy dV/dq ) )^1 -------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-3/(2*dy));                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+     alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-3/(2*dy));

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(4/(2*dy));                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+2)+  alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(4/(2*dy));
 
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-1/(2*dy));            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+     alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*dz*(-3/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+  alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*dz*(4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+ alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*dz*(-1/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,1)*difY1(ii)*0.5*dz*(-1/(2*dy));                
end
            
end 




%------- (17) (-3/(2*dy)) Kp2 ( dQy H dY1/dx int ( dZy dV/dz ) )^1 --------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZy(ii,1,1) - alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,1);                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZy(ii,1,2) - alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZy(ii,1,1) - alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dz*d2Zyz(ii,1,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZy(ii,1,kk) - alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,kk);                
end

end




%------- (18) (-3/(2*dy)) Kp2 ( dQy H dY1/dx ( int ( dZz dW/dz ) )^1 -------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);                             
MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB((ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp2*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

end
      
end 




%------- (19) (4/(2*dy)) dQy^1 ( H int ( dQy dU/dq ) )^2 -------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)-     alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)-     alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)-    alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)^2*HIC(ii,2)*0.5*dz/(2*dy);                
end
            
end 




%-------- (20) (4/(2*dy)) dQy^1 ( H int ( dZy dU/dz ) )^2 ------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)-alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZy(ii,2,1) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zyz(ii,2,1);                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZy(ii,2,2) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zyz(ii,2,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)- alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZy(ii,2,1) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zyz(ii,2,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)- alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dz*d2Zyz(ii,2,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZy(ii,2,kk) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zyz(ii,2,kk);                
end

end




%----------- (21) (4/(2*dy)) dQy^1 ( H ( int (dV/dx) )^2 -------------;


for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)-alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz/(2*dx);                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+2)-alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz/(2*dx);

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=    MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+    alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz/(2*dx);            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+2)=    MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+2)+    alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)- alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)- alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)-alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+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*dz*(-4/(2*dx));

MB((Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)=MB((Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)+alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(3/(2*dx));            
MB((Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+2)=MB((Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+2)+alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(3/(2*dx));



for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*dz*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*dz*(3/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(Nx)*HIC(Nx,2)*0.5*dz*(3/(2*dx));         
end




%--------- (22) (4/(2*dy)) dQy^1 ( H int ( dQx dV/dq ) )^2 ----------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=     MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)-     alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);
 
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)-     alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)-    alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                
end
            
end 



%--------- (23) (4/(2*dy)) dQy^1 ( H int ( dZx dV/dz ) )^2 ---------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZx(ii,2,1) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zxz(ii,2,1);                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+2)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZx(ii,2,2) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zxz(ii,2,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)- alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZx(ii,2,1) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zxz(ii,2,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)- alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dz*d2Zxz(ii,2,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZx(ii,2,kk) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zxz(ii,2,kk);                
end

end




%------- (24) (-1/(2*dy)) dQy^1 ( H int ( dQy dU/dq ) )^3 -------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)-  alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)-  alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+1)+alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);            
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+2)+alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)-   alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)-   alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)-  alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)+alfa2*(-1/(2*dy))*dQy(ii)^2*HIC(ii,3)*0.5*dz/(2*dy);                
end
            
end 



%-------- (25) (-1/(2*dy)) dQy^1 ( H int ( dZy dU/dz ) )^3 ------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)-alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZy(ii,3,1) - alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz*d2Zyz(ii,3,1);                             
MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZy(ii,3,2) - alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz*d2Zyz(ii,3,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)- alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZy(ii,3,1) - alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz*d2Zyz(ii,3,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)- alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dz*d2Zyz(ii,3,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZy(ii,3,kk) - alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz*d2Zyz(ii,3,kk);                
end

end




%----------- (26) (-1/(2*dy)) dQy^1 ( H ( int (dV/dx) )^3 -------------;


for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)-alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);                             
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+2)-alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);

MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)=    MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+    alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)=    MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)+    alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)- alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)- alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)-alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)=     MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)=    MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB((Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)=MB((Nx-1)*Ny*Nz+2,Nx*Ny*N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z+(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQy(Nx)*HIC(Nx,3)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQy(Nx)*HIC(Nx,3)*dz*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(Nx)*HIC(Nx,3)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQy(Nx)*HIC(Nx,3)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)= MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQy(Nx)*HIC(Nx,3)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(Nx)*HIC(Nx,3)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB((Nx-1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*Nz+1)+alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);            
MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+2)=MB((ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+2)+alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-   alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)-   alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQx(ii,3)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)-  alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*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(ii,3)*0.5*dz*d2Zxz(ii,3,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)- alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dz*d2Zxz(ii,3,p); 
end                                            

MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB((ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZx(ii,3,kk) - alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*0.5*dz*d2Zxz(ii,3,kk);                
end

end




%------------------- (29) Kp1 H dZ/dx dU/dx  ---------------------;

for ii=2:1:Nx-1 
for kk=2:1:Nz 
MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)+alfa2*Kp1*HIC(ii,1)*dZx(ii,1,kk)*(-1/(2*dx)); 
MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=    MB((ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+    alfa2*Kp1*HIC(ii,1)*dZx(ii,1,kk)*(1/(2*dx)); 
end 
end


%-------- i=Nx -------;

for kk=2:1:Nz 
MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*dZx(Nx,1,kk)*(1/(2*dx)); 
MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB((Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*dZx(Nx,1,kk)*(-4/(2*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ny*Nz+2)=MB((ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);

end 



for ii=2:1:Nx 
    
for kk=3:1:Nz 
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(ii,1);  
end

MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB((ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);
end

end 




%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++ The second equation +++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%------------- (1) Kp1 d/dx ( H dY1/dx ( int (dU/dx) ) ----------------;

%--------------- (1,a) Kp1 d(H dY1/dx)/dx int (dU/dx)  -----------------;

for ii=2:1:Nx-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)-alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz/(2*dx);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)-alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz/(2*dx);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+1)+    alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz/(2*dx);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+    alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)-  alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)-  alfa2*Kp1*d2Y1xHx(ii,1)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)-alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+  alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+  alfa2*Kp1*d2Y1xHx(ii,1)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=MB(Nx*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*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+ alfa2*Kp1*0.5*d2Y1xHx(Nx,1)*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+ alfa2*Kp1*d2Y1xHx(Nx,1)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*0.5*d2Y1xHx(Nx,1)*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+ alfa2*Kp1*0.5*d2Y1xHx(Nx,1)*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+ alfa2*Kp1*d2Y1xHx(Nx,1)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*0.5*d2Y1xHx(Nx,1)*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)=MB(Nx*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/dx^2;

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+1)+    alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz/dx^2;            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+    alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz/dx^2;

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)+ alfa2*Kp1*HIC(ii,1)*difY1(ii)*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*Kp1*HIC(ii,1)*difY1(ii)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)- alfa2*Kp1*HIC(ii,1)*difY1(ii)*dz*2/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)-alfa2*Kp1*HIC(ii,1)*difY1(ii)*dz/dx^2;                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+         alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+         alfa2*Kp1*HIC(ii,1)*difY1(ii)*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+        alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz/dx^2;         
end
            
end 


%------- i=Nx ------;


MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(-1/dx^2);                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-4)*Ny*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(-1/dx^2);

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+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

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dz*(-1/dx^2); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-4)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(-1/dx^2);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(4/dx^2);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dz*(4/dx^2); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(4/dx^2);                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(-5/dx^2);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dz*(-5/dx^2); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(-5/dx^2);         
end


for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(2/dx^2);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dz*(2/dx^2); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*(2/dx^2);         
end




%--------- (2) Kp1 d/dx ( H dY1/dx ( int ( dQx dU/dq ) ) -----------;

%--------- (2,a) Kp1 d/dx ( H dY1/dx dQx ) int ( dU/dq ) ------------;

for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)+     alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(-3/(2*dy));                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(-3/(2*dy));

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(4/(2*dy));                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(4/(2*dy));
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(-1/(2*dy));            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)+     alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)+     alfa2*Kp1*d2QxHY1x(ii,1)*dz*(-3/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+    alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)+  alfa2*Kp1*d2QxHY1x(ii,1)*dz*(4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+ alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*d2QxHY1x(ii,1)*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*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)*Ny*Nz+2,ii*Ny*Nz+2*Nz+1)+    alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(4*dx*dy));                        
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+2)+    alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)+      alfa2*Kp1*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(3/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+      alfa2*Kp1*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(4*dx*dy));                
end

end



%------- i=Nx ------;


MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)+     alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)+     alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));
 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+Nz+1)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+Nz+1)+  alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(4/(4*dx*dy));            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+Nz+2)=  MB(N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(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+Nz+2)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+Nz+2)+  alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(12/(4*dx*dy));

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                        
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));




for kk=3:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+      alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(12/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+      alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(12/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-16/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(4/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+      alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-9/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+      alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-9/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+     alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-9/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)+   alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)+   alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)+  alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                
end



%-------- (3) Kp1 d/dx ( H dY1/dx ( int ( dZx dU/dz ) ) -----------;

%--------- (3,a) Kp1 d(H dY1/dx)/dx  int ( dZx dU/dz ) ------------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*Kp1*d2Y1xHx(ii,1)*dZx(ii,1,1) - alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz*d2Zxz(ii,1,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*Kp1*d2Y1xHx(ii,1)*dZx(ii,1,2) - alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz*d2Zxz(ii,1,2);


for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*Kp1*d2Y1xHx(ii,1)*dZx(ii,1,1) - alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)- alfa2*Kp1*d2Y1xHx(ii,1)*dz*d2Zxz(ii,1,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+alfa2*Kp1*d2Y1xHx(ii,1)*dZx(ii,1,kk) - alfa2*Kp1*0.5*d2Y1xHx(ii,1)*dz*d2Zxz(ii,1,kk);                
end

end




%----------- (3,b) Kp1 H dY1/dx d/dx ( int ( dZx dU/dz ) ) --------------;


for ii=2:1:Nx-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)+alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii-1,1,1)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii-1,1,1)/(2*dx);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+2)-alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii-1,1,2)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii-1,1,2)/(2*dx);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+1)-    alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii+1,1,1)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii+1,1,1)/(2*dx);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2)+    alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii+1,1,2)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii+1,1,2)/(2*dx);

end



for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+1)+ alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii-1,1,1)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii-1,1,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)+ alfa2*Kp1*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii-1,1,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)-alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii-1,1,kk)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii-1,1,kk)/(2*dx);                
end


for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)- alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii+1,1,1)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii+1,1,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)- alfa2*Kp1*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii+1,1,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+alfa2*Kp1*HIC(ii,1)*difY1(ii)*dZx(ii+1,1,kk)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii+1,1,kk)/(2*dx);         
end
            
end 



%------- i=Nx ------;


MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)-alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx-2,1,1)*(1/(2*dx)) -  alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx-2,1,1)*(1/(2*dx));                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+2)+alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx-2,1,2)*(1/(2*dx)) -  al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z+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)- alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx-2,1,1)*(1/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx-2,1,1)*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)- alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx-2,1,p)*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx-2,1,kk)*(1/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx-2,1,kk)*(1/(2*dx));                
end


for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)- alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx-1,1,1)*(-4/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx-1,1,1)*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)- alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx-1,1,p)*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx-1,1,kk)*(-4/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx-1,1,kk)*(-4/(2*dx));         
end


for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)- alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx,1,1)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx,1,1)*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)- alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx,1,p)*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*Kp1*HIC(Nx,1)*difY1(Nx)*dZx(Nx,1,kk)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zxz(Nx,1,kk)*(3/(2*dx));         
end




%--------- (4) Kp2 d/dx ( H dY1/dx ( int ( dQy dV/dq ) ) ------------;

%--------- (4,a) Kp2 d/dx ( H dY1/dx dQy ) int ( dV/dq ) ------------;

for ii=2:1:Nx

MB(Nx*Ny*Nz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1)*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*Kp2*0.5*d2QyHY1x(ii,1)*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+     alfa2*Kp2*d2QyHY1x(ii,1)*dz*(-3/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*Kp2*0.5*d2QyHY1x(ii,1)*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*Kp2*0.5*d2QyHY1x(ii,1)*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+  alfa2*Kp2*d2QyHY1x(ii,1)*dz*(4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+ alfa2*Kp2*0.5*d2QyHY1x(ii,1)*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*d2QyHY1x(ii,1)*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*d2QyHY1x(ii,1)*dz*(-1/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*d2QyHY1x(ii,1)*dz*(-1/(2*dy));                
end
            
end 



%---------- (4,b) Kp2 H dY1/dx dQy d/dx ( int ( dV/dq ) ) ------------;

for ii=2:1:Nx-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+     alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(3/(4*dx*dy));                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*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Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)+      alfa2*Kp2*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(3/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)+      alfa2*Kp2*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-1/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-1/(4*dx*dy));                
end

end



%------- i=Nx ------;


MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+     alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy));                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2)+     alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy));
 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz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Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)+      alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(12/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+      alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(12/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-16/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(4/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+      alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-9/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)+      alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-9/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+     alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-9/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)+   alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)+   alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)+  alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dQy(Nx)*dz*(-3/(4*dx*dy));                
end



%----------- (5) Kp2 d/dx ( H dY1/dx ( int ( dZy dV/dz ) ) -------------;

%------------ (5,a) Kp2 d(H dY1/dx)/dx  int ( dZy dV/dz ) --------------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*Kp2*d2Y1xHx(ii,1)*dZy(ii,1,1) - alfa2*Kp2*0.5*d2Y1xHx(ii,1)*dz*d2Zyz(ii,1,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*Kp2*d2Y1xHx(ii,1)*dZy(ii,1,2) - alfa2*Kp2*0.5*d2Y1xHx(ii,1)*dz*d2Zyz(ii,1,2);


for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*Kp2*d2Y1xHx(ii,1)*dZy(ii,1,1) - alfa2*Kp2*0.5*d2Y1xHx(ii,1)*dz*d2Zyz(ii,1,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*Kp2*d2Y1xHx(ii,1)*dz*d2Zyz(ii,1,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*Kp2*d2Y1xHx(ii,1)*dZy(ii,1,kk) - alfa2*Kp2*0.5*d2Y1xHx(ii,1)*dz*d2Zyz(ii,1,kk);                
end

end



%------------ (5,b) Kp2 H dY1/dx d/dx ( int ( dZy dV/dz ) ) --------------;

for ii=2:1:Nx-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+alfa2*Kp2*HIC(ii,1)*difY1(ii)*dZy(ii-1,1,1)/(2*dx) + alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zyz(ii-1,1,1)/(2*dx);                             
MB(N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p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)+ alfa2*Kp2*HIC(ii,1)*difY1(ii)*dz*d2Zyz(ii-1,1,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa2*Kp2*HIC(ii,1)*difY1(ii)*dZy(ii-1,1,kk)/(2*dx) + alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zyz(ii-1,1,kk)/(2*dx);                
end


for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)- alfa2*Kp2*HIC(ii,1)*difY1(ii)*dZy(ii+1,1,1)/(2*dx) - alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zyz(ii+1,1,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)- alfa2*Kp2*HIC(ii,1)*difY1(ii)*dz*d2Zyz(ii+1,1,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+kk)+alfa2*Kp2*HIC(ii,1)*difY1(ii)*dZy(ii+1,1,kk)/(2*dx) - alfa2*Kp2*0.5*HIC(ii,1)*difY1(ii)*dz*d2Zyz(ii+1,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-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)- alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dZy(Nx,1,1)*(3/(2*dx)) - alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zyz(Nx,1,1)*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)- alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dz*d2Zyz(Nx,1,p)*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+alfa2*Kp2*HIC(Nx,1)*difY1(Nx)*dZy(Nx,1,kk)*(3/(2*dx)) - alfa2*Kp2*0.5*HIC(Nx,1)*difY1(Nx)*dz*d2Zyz(Nx,1,kk)*(3/(2*dx));         
end




%---------- (6) Kp2 d/dx ( H dY1/dx ( int ( dZz dW/dz ) ) ------------;

%--------- (6,a) Kp2 d(H dY1/dx)/dx ( int ( dZz dW/dz ) ) -------------;

for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*Kp2*d2Y1xHx(ii,1)*dZz(ii,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*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IC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+p)- alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+kk)-alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+1)+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(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*dz*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQx(Nx,1)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(3/(2*dx));         
end




%------- (8) (-3/(2*dy)) Kp1 ( dQx H dY1/dx int ( dQx dU/dq ) )^1 -------;

for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)+     alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-3/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+    alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)+  alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+ alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));                
end
            
end 




%-------- (9) (-3/(2*dy)) Kp1 ( dQx H dY1/dx int ( dZx dU/dz ) )^1 ------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZx(ii,1,1) - alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZx(ii,1,2) - alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,2);


for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZx(ii,1,1) - alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)- alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii,1,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZx(ii,1,kk) - alfa2*(-3/(2*dy))*Kp1*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,kk);                
end

end



%------- (10) (-3/(2*dy)) Kp2 ( dQx H dY1/dx int ( dQy dV/dq ) )^1 -------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-3/(2*dy));                             
MB(Nx*Ny*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/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+     alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-3/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+  alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+ alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-1/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-1/(2*dy));                
end
            
end 




%------- (11)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ii,1)*difY1(ii)*dz*d2Zyz(ii,1,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZy(ii,1,kk) - alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,kk);                
end

end




%------- (12) (-3/(2*dy)) Kp2 ( dQx H dY1/dx ( int ( dZz dW/dz ) )^1 -------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZz(ii,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*Kp2*dQx(ii,1)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*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IC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)-     alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)-    alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                
end
            
end 



%-------- (14) (4/(2*dy)) dQx^1 ( H int ( dZy dU/dz ) )^2 ------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii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2Zyz(ii,2,kk);                
end

end




%----------- (15) (4/(2*dy)) dQx^1 ( H ( int (dV/dx) )^2 ------------;


for ii=2:1:Nx-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)-alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+2)-alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+    alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+Nz+2)+    alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)- alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)- alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)-alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*0.5*dz/(2*dx);         
end
            
end 


%--- i=Nx ---;

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*N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Nz+Nz+2)+alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*0.5*dz*(3/(2*dx));



for kk=3:1:Nz

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*dz*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQx(Nx,1)*HIC(Nx,2)*0.5*dz*(3/(2*dx));         
end




%--------- (16) (4/(2*dy)) dQx^1 ( H int ( dQx dV/dq ) )^2 ----------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)-     alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)-     alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)-    alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(4/(2*dy))*dQx(ii,1)*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                
end
            
end 




%--------- (17) (4/(2*dy)) dQx^1 ( H int ( dZx dV/dz ) )^2 ---------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*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-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)-   alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)-  alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)+alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                
end
            
end 



%-------- (19) (-1/(2*dy)) dQx^1 ( H int ( dZy dU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Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)- alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)- alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)-alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)+alfa2*(-1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3)*0.5*dz*(3/(2*dx));            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+2)+alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*0.5*dz*(3/(2*dx));



for kk=3:1:Nz

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQx(Nx,1)*HIC(Nx,3)*dz*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*N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Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-   alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)-   alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQx(ii,3)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)-  alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dQx(ii,3)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz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*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)- alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dz*d2Zxz(ii,3,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*dZx(ii,3,kk) - alfa2*(-1/(2*dy))*dQx(ii,1)*HIC(ii,3)*0.5*dz*d2Zxz(ii,3,kk);                
end

end





%------- (23) (-3/(2*dy)) ( dQy H dY1/dx int ( dQy dU/dq ) )^1 -------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-3/(2*dy));                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-3/(2*dy));

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(4/(2*dy));                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(4/(2*dy));
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-1/(2*dy));            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-3/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+    alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*dz*(-1/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQy(ii)*0.5*dz*(-1/(2*dy));                
end
            
end 



%------- (24) (-3/(2*dy)) ( dQy H dY1/dx int ( dZy dU/dz ) )^1 --------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZy(ii,1,1) - alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZy(ii,1,2) - alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,2);


for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZy(ii,1,1) - alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zyz(ii,1,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)= MB(Nx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nz+2,Nx*Ny*Nz+ii*Ny*Nz+2)+    alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+1)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+p)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+1)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+p)+ alf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ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(3/(2*dx));            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,Nx*Ny*Nz+(Nx-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(3/(2*dx));



for kk=3:1:Nz-1

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(Nx,1)*difY1(Nx)*dz*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx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0.5*dz*(4/(2*dy));
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-3/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*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*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZx(ii,1,1) - alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dz*d2Zxz(ii,1,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZx(ii,1,kk) - alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz*d2Zxz(ii,1,kk);                
end

end




%------- (28) (4/(2*dy)) Kp1 dQy^1 ( H int ( dQy dV/dq ) )^2 -------;

for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)-     alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)-     alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)-    alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                
end
            
end 




%-------- (29) (4/(2*dy)) Kp1 dQy^1 ( H int ( dZy dV/dz ) )^2 ------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*dZy(ii,2,1) - alfa2*(4/(2*dy))*dQy(ii)*Kp1*HIC(ii,2)*0.5*dz*d2Zyz(ii,2,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+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ny*Nz+Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+1)-alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+Nz+2)-alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+1)+    alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+Nz+2)+    alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+1)- alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+p)- alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+Nz+kk)-alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz/(2*dx);         
end
            
end 


%--- i=Nx ---;

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+Nz+1)+alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*0.5*dz*(1/(2*dx));                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+Nz+2)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-3)*Ny*Nz+Nz+2)+alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*0.5*dz*(1/(2*dx));
 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-2)*Ny*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(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+1)+ alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+p)+ alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*dz*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,2)*0.5*dz*(3/(2*dx));         
end




%--------- (31) (4/(2*dy)) Kp2 dQy^1 ( H int ( dQx dU/dq ) )^2 ----------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)-     alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)+alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)-     alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)=      MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+p)-     alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)-    alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dQx(ii,2)*0.5*dz/(2*dy);                
end
            
end 




%--------- (32) (4/(2*dy)) Kp2 dQy^1 ( H int ( dZx dU/dz ) )^2 ---------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)-alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dZx(ii,2,1) - alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz*d2Zxz(ii,2,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)+alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dZx(ii,2,2) - alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz*d2Zxz(ii,2,2);


for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)- alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dZx(ii,2,1) - alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*0.5*dz*d2Zxz(ii,2,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)- alfa2*(4/(2*dy))*dQy(ii)*Kp2*HIC(ii,2)*dz*d2Zxz(ii,2,p); 
end                                            

MB(Nx*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*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-   alfa2*(-1/(2*dy))*dQy(ii)*Kp1*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)-   alfa2*(-1/(2*dy))*dQy(ii)*Kp1*HIC(ii,3)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)-  alfa2*(-1/(2*dy))*dQy(ii)*Kp1*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*(-1/(2*dy))*dQy(ii)*Kp1*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*(-1/(2*dy))*dQy(ii)*Kp1*HIC(ii,3)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*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ny*Nz+2*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,ii*Ny*Nz+2*Nz+2)+    alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+1)- alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+p)- alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-2)*Ny*Nz+2*Nz+kk)-alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,ii*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*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1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(3/(2*dx));            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,(Nx-1)*Ny*Nz+2*Nz+2)+alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(3/(2*dx));



for kk=3:1:Nz

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*dz*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,(Nx-1)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,3)*0.5*dz*(3/(2*dx));         
end




%--------- (37) (-1/(2*dy)) Kp2 dQy^1 ( H int ( dQx dU/dq ) )^3 ----------;

for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+1)-  alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+Nz+2)-  alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+1)+alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+3*Nz+2)+alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+1)-   alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)=   MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+p)-   alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+Nz+kk)-  alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+3*Nz+kk)+alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dQx(ii,3)*0.5*dz/(2*dy);                
end
            
end




%--------- (38) (-1/(2*dy)) Kp2 dQy^1 ( H int ( dZx dU/dz ) )^3 ---------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+1)-alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dZx(ii,3,1) - alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz*d2Zxz(ii,3,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dZx(ii,3,2) - alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz*d2Zxz(ii,3,2);


for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+1)- alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dZx(ii,3,1) - alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz*d2Zxz(ii,3,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+p)- alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dz*d2Zxz(ii,3,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*dZx(ii,3,kk) - alfa2*(-1/(2*dy))*dQy(ii)*Kp2*HIC(ii,3)*0.5*dz*d2Zxz(ii,3,kk);                
end

end




%------- (39) (-1/(2*dy)) Kp2 dQy^1 ( H ( int ( dZz dW/dz ) )^3 -------;


for ii=2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(ii)*dZx(ii,1,Nz)*(-4/(2*dz)); 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz)-   alfa2*difY1(ii)*dZx(ii,1,Nz)*(3/(2*dz)); 
end 




%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ + KpE dens Freq^2 V +++++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;



for ii=2:1:Nx 
    
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);

end 



for ii=2:1:Nx 

    
for kk=3:1:Nz 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);

for p=2:1:kk-1                                                         
 MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(ii,1);  
end

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);
end

end 



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++ The third equation ++++++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) d/dx ( H ( int ( dZz dU/dz ) ) ----------------;

%----------- (1,a) dH/dx ( int ( dZz dU/dz ) ) ----------------;

for ii=2:1:Nx

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*dHx(ii,1)*dZz(ii,1);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*dHx(ii,1)*dZz(ii,1);

end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*dHx(ii,1)*dZz(ii,1);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+alfa2*dHx(ii,1)*dZz(ii,1);

end
      
end 


%----------- (1,b) H d/dx ( int ( dZz dU/dz ) ) --------------;

for ii=2:1:Nx-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-2)*Ny*Nz+1)=MB(2*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B(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)-alfa2*0.5*dHx(ii,1)*dz/(2*dx);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)-alfa2*0.5*dHx(ii,1)*dz/(2*dx);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+1)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+1)+    alfa2*0.5*dHx(ii,1)*dz/(2*dx);            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)+    alfa2*0.5*dHx(ii,1)*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)- alfa2*0.5*dHx(ii,1)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)- alfa2*dHx(ii,1)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa2*0.5*dHx(ii,1)*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)+ alfa2*0.5*dHx(ii,1)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)+ alfa2*dHx(ii,1)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)+alfa2*0.5*dHx(ii,1)*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+alfa2*0.5*dHx(Nx,1)*dz*(1/(2*dx));                             
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2)+alfa2*0.5*dHx(Nx,1)*dz*(1/(2*dx));
 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1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,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+alfa2*0.5*dHx(Nx,1)*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+ alfa2*0.5*dHx(Nx,1)*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+ alfa2*dHx(Nx,1)*dz*(-4/(2*dx)); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa2*0.5*dHx(Nx,1)*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+ alfa2*0.5*dHx(Nx,1)*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*N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*Nz+ii*Ny*Nz+1)+    alfa2*0.5*HIC(ii,1)*dz/dx^2;            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)+    alfa2*0.5*HIC(ii,1)*dz/dx^2;

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+ alfa2*0.5*HIC(ii,1)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)+ alfa2*HIC(ii,1)*dz/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)+alfa2*0.5*HIC(ii,1)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*HIC(ii,1)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*HIC(ii,1)*dz*2/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)-alfa2*HIC(ii,1)*dz/dx^2;                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)+ alfa2*0.5*HIC(ii,1)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)+ alfa2*HIC(ii,1)*dz/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)+alfa2*0.5*HIC(ii,1)*dz/dx^2;         
end
            
end 


%------- i=Nx ------;


MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+1)+alfa2*0.5*HIC(Nx,1)*dz*(-1/dx^2);                             
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(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ny*Nz+2,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2)+alfa2*0.5*HIC(Nx,1)*dz*(2/dx^2);



for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+1)+ alfa2*0.5*HIC(Nx,1)*dz*(-1/dx^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+p)+ alfa2*HIC(Nx,1)*dz*(-1/dx^2); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-4)*Ny*Nz+kk)+alfa2*0.5*HIC(Nx,1)*dz*(-1/dx^2);                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+ alfa2*0.5*HIC(Nx,1)*dz*(4/dx^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)+ alfa2*HIC(Nx,1)*dz*(4/dx^2); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+alfa2*0.5*HIC(Nx,1)*dz*(4/dx^2);                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+ alfa2*0.5*HIC(Nx,1)*dz*(-5/dx^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+ alfa2*HIC(Nx,1)*dz*(-5/dx^2); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa2*0.5*HIC(Nx,1)*dz*(-5/dx^2);         
end


for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+ alfa2*0.5*HIC(Nx,1)*dz*(2/dx^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny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nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*0.5*d2QxHx(ii,1)*dz*(-1/(2*dy));            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*0.5*d2QxHx(ii,1)*dz*(-1/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*0.5*d2QxHx(ii,1)*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+     alfa2*d2QxHx(ii,1)*dz*(-3/(2*dy));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*0.5*d2QxHx(ii,1)*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*0.5*d2QxHx(ii,1)*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+  alfa2*d2QxHx(ii,1)*dz*(4/(2*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+ alfa2*0.5*d2QxHx(ii,1)*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*0.5*d2QxHx(ii,1)*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*d2QxHx(ii,1)*dz*(-1/(2*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*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ny*Nz+ii*Ny*Nz+2*Nz+1)+alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy));                        
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)+alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+      alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)+      alfa2*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)+     alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)+   alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)+   alfa2*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)+  alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)+ alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)+ alfa2*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)+alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)+      alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)+      alfa2*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)+     alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+   alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+p)+   alfa2*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)+  alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+ alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)+ alfa2*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+kk)+alfa2*0.5*HIC(ii,1)*dQx(ii,1)*dz*(-1/(4*dx*dy));                
end

end



%------- i=Nx ------;


MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+     alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                             
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(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x*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+2)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+2)+alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));




for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+      alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)+      alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));  
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+     alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)+   alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)+   alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)+  alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(-1/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-1/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+      alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+      alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+     alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)+   alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)+   alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(-16/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)+  alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(4/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+      alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-9/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)+      alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(-9/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+     alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-9/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)+   alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)+   alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)+  alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+kk)+alfa2*0.5*HIC(Nx,1)*dQx(Nx,1)*dz*(-3/(4*dx*dy));                
end





%---------- (4) d/dx ( H ( int ( dZx dW/dz ) ) ----------------;

%------------ (4,a) dH/dx int ( dZx dW/dz ) ----------------;


for ii=2:1:Nx

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*dHx(ii,1)*dZx(ii,1,1) - alfa2*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,1);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*dHx(ii,1)*dZx(ii,1,2) - alfa2*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,2);


for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*dHx(ii,1)*dZx(ii,1,1) - alfa2*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*dHx(ii,1)*dz*d2Zxz(ii,1,p); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+alfa2*dHx(ii,1)*dZx(ii,1,kk) - alfa2*0.5*dHx(ii,1)*dz*d2Zxz(ii,1,kk);                
end

end



%------------ (4,b) H d/dx ( int ( dZx dW/dz ) ) --------------;


for ii=2:1:Nx-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+alfa2*HIC(ii,1)*dZx(ii-1,1,1)/(2*dx) + alfa2*0.5*HIC(ii,1)*dz*d2Zxz(ii-1,1,1)/(2*dx);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*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*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa2*HIC(ii,1)*dZx(ii-1,1,kk)/(2*dx) + alfa2*0.5*HIC(ii,1)*dz*d2Zxz(ii-1,1,kk)/(2*dx);                
end


for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)- alfa2*HIC(ii,1)*dZx(ii+1,1,1)/(2*dx) - alfa2*0.5*HIC(ii,1)*dz*d2Zxz(ii+1,1,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)- alfa2*HIC(ii,1)*dz*d2Zxz(ii+1,1,p)/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)+alfa2*HIC(ii,1)*dZx(ii+1,1,kk)/(2*dx) - alfa2*0.5*HIC(ii,1)*dz*d2Zxz(ii+1,1,kk)/(2*dx);         
end
            
end 



%------- i=Nx ------;


MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)-alfa2*HI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*Ny*Nz+(Nx-2)*Ny*Nz+1)- alfa2*HIC(Nx,1)*dZx(Nx-1,1,1)*(-4/(2*dx)) - alfa2*0.5*HIC(Nx,1)*dz*d2Zxz(Nx-1,1,1)*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)- alfa2*HIC(Nx,1)*dz*d2Zxz(Nx-1,1,p)*(-4/(2*dx)); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa2*HIC(Nx,1)*dZx(Nx-1,1,kk)*(-4/(2*dx)) - alfa2*0.5*HIC(Nx,1)*dz*d2Zxz(Nx-1,1,kk)*(-4/(2*dx));         
end


for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)- alfa2*HIC(Nx,1)*dZx(Nx,1,1)*(3/(2*dx)) - alfa2*0.5*HIC(Nx,1)*dz*d2Zxz(Nx,1,1)*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)- alfa2*HIC(Nx,1)*dz*d2Zxz(Nx,1,p)*(3/(2*dx)); 
end                                            

MB(2*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Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)-alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)-alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+1)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+1)+    alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)+    alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx); 

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)- alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)- alfa2*dQx(ii,1)*d1Hq(ii,1)*dz/(2*dx);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)+     alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)+     alfa2*dQx(ii,1)*d1Hq(ii,1)*dz/(2*dx); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)+    alfa2*dQx(ii,1)*0.5*d1Hq(ii,1)*dz/(2*dx);                
end

end 


%------- i=Nx ------;

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+1)+alfa2*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(1/(2*dx));                             
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny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*d1Hq(Nx,1)*dz*(1/(2*dx));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)+ alfa2*dQx(Nx,1)*d1Hq(Nx,1)*dz*(1/(2*dx));  
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+alfa2*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(1/(2*dx));                
end


for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+ alfa2*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(-4/(2*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+ alfa2*dQx(Nx,1)*d1Hq(Nx,1)*dz*(-4/(2*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa2*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(-4/(2*dx));                
end


for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+ alfa2*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(3/(2*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)+ alfa2*dQx(Nx,1)*d1Hq(Nx,1)*dz*(3/(2*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+alfa2*dQx(Nx,1)*0.5*d1Hq(Nx,1)*dz*(3/(2*dx));                
end



%----------- (6,b) dQx H d/dq ( int ( dW/dx ) ) --------------;


for ii=2:1:Nx-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+     alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)+     alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));

MB(2*Nx*Ny*Nz+(ii-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Ny*Nz+2)+         alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-3/(4*dy*dx)); 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+      alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(4/(4*dy*dx));            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+2)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+2)+      alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(4/(4*dy*dx));

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+    alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-1/(4*dy*dx));            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+2)+    alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-1/(4*dy*dx));

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)+      alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)+      alfa2*dQx(ii,1)*HIC(ii,1)*dz*(3/(4*dy*dx));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)+     alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(3/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+1)+   alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+p)+   alfa2*dQx(ii,1)*HIC(ii,1)*dz*(-4/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+Nz+kk)+  alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+1)+ alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(1/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+p)+ alfa2*dQx(ii,1)*HIC(ii,1)*dz*(1/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2*Nz+kk)+alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(1/(4*dy*dx));                
end


for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+1)+      alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-3/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+p)+      alfa2*dQx(ii,1)*HIC(ii,1)*dz*(-3/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+kk)+     alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-3/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+1)+   alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(4/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+p)+   alfa2*dQx(ii,1)*HIC(ii,1)*dz*(4/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+Nz+kk)+  alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+1)+ alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*(-1/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz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Nz+(Nx-3)*Ny*Nz+p)+      alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(-3/(4*dy*dx));  
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+     alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+1)+   alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+p)+   alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(4/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+Nz+kk)+  alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+1)+ alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-1/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+p)+ alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(-1/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+2*Nz+kk)+alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-1/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+      alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+      alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(12/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+     alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+1)+   alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-16/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+p)+   alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(-16/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+Nz+kk)+  alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-16/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+1)+ alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+p)+ alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(4/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+2*Nz+kk)+alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(4/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+1)+      alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-9/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+p)+      alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(-9/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk)+     alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-9/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+1)+   alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+p)+   alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(12/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+Nz+kk)+  alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(12/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+1)+ alfa2*dQx(Nx,1)*0.5*HIC(Nx,1)*dz*(-3/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+2*Nz+p)+ alfa2*dQx(Nx,1)*HIC(Nx,1)*dz*(-3/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*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*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+alfa2*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-1/(2*dy));            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-1/(2*dy));

end


for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+      alfa2*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-3/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+      alfa2*dQx(ii,1)*d2QxHq(ii,1)*dz*(-3/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+     alfa2*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-3/(2*dy));                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+   alfa2*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(4/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+   alfa2*dQx(ii,1)*d2QxHq(ii,1)*dz*(4/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+  alfa2*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(4/(2*dy));                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*dQx(ii,1)*d2QxHq(ii,1)*0.5*dz*(-1/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*dQx(ii,1)*d2QxHq(ii,1)*dz*(-1/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz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C(ii,1)*dz*(2/dy^2); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(2/dy^2);                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+   alfa2*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-5/dy^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+   alfa2*dQx(ii,1)^2*HIC(ii,1)*dz*(-5/dy^2); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+  alfa2*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-5/dy^2);                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(4/dy^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*dQx(ii,1)^2*HIC(ii,1)*dz*(4/dy^2); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(4/dy^2);         
end


for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-1/dy^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)+ alfa2*dQx(ii,1)^2*HIC(ii,1)*dz*(-1/dy^2); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+kk)+alfa2*dQx(ii,1)^2*HIC(ii,1)*0.5*dz*(-1/dy^2);         
end

            
end 




%---------- (8) dQx d/dq ( H ( int ( dZx dW/dz ) ) ---------------;

%------------ (8,a) dQx dH/dq  int ( dZx dU/dz ) ----------------;


for ii=2:1:Nx

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)-alfa2*dQx(ii,1)*d1Hq(ii,1)*dZx(ii,1,1) - alfa2*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zxz(ii,1,1);            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2)+alfa2*dQx(ii,1)*d1Hq(ii,1)*dZx(ii,1,2) - alfa2*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zxz(ii,1,2);

end


for ii=2:1:Nx

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)- alfa2*dQx(ii,1)*d1Hq(ii,1)*dZx(ii,1,1) - alfa2*dQx(ii,1)*d1Hq(ii,1)*0.5*dz*d2Zxz(ii,1,1);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)- alfa2*dQx(ii,1)*d1Hq(ii,1)*dz*d2Zxz(ii,1,p); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii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ny*Nz+(ii-1)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)-      alfa2*dQx(ii,1)*HIC(ii,1)*dz*d2Zxz(ii,1,p)*(-3/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+     alfa2*dQx(ii,1)*HIC(ii,1)*dZx(ii,1,kk)*(-3/(2*dy)) - alfa2*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zxz(ii,1,kk)*(-3/(2*dy));                
end


for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-   alfa2*dQx(ii,1)*HIC(ii,1)*dZx(ii,2,1)*(4/(2*dy)) - alfa2*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zxz(ii,2,1)*(4/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)-   alfa2*dQx(ii,1)*HIC(ii,1)*dz*d2Zxz(ii,2,p)*(4/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+  alfa2*dQx(ii,1)*HIC(ii,1)*dZx(ii,2,kk)*(4/(2*dy)) - alfa2*dQx(ii,1)*HIC(ii,1)*0.5*dz*d2Zxz(ii,2,kk)*(4/(2*dy));         
end


for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)- alfa2*dQx(ii,1)*HIC(ii,1)*dZx(ii,3,1)*(-1/(2*dy)) - alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,3,1)*(-1/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)- alfa2*dQx(ii,1)*HIC(ii,1)*dz*d2Zxz(ii,3,p)*(-1/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*dQx(ii,1)*HIC(ii,1)*dZx(ii,3,kk)*(-1/(2*dy)) - alfa2*dQx(ii,1)*0.5*HIC(ii,1)*dz*d2Zxz(ii,3,kk)*(-1/(2*dy));         
end


end 




%------- (9) (-3/(2*dy)) ( dQy H dY1/dx ( int ( dZz dU/dz ) )^1 -------;


for ii=2:1:Nx

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+1)-alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,(ii-1)*Ny*Nz+2)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+1)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,(ii-1)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dZz(ii,1);

end
      
end 




%--------- (10) (-3/(2*dy)) ( dQy H dY1/dx int (dW/dx) )^1  ---------;


for ii=2:1:Nx-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)-alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+2)-alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+1)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+1)+    alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+2)+    alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+1)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+p)- alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+kk)-alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz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+(Nx-3)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*dz*(1/(2*dx)); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+1)+ alfa2*(-3/(2*dy))*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+p)+ alfa2*(-3/(2*dy))*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*dz*(-4/(2*dx)); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+kk)+alfa2*(-3/(2*dy))*dQy(Nx)*HIC(Nx,1)*difY1(Nx)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz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ny*Nz+1)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+1)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)+     alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-3/(2*dy));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+    alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-3/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)+  alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(4/(2*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(4/(2*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*dz*(-1/(2*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)+alfa2*(-3/(2*dy))*dQy(ii)*HIC(ii,1)*difY1(ii)*dQx(ii,1)*0.5*dz*(-1/(2*dy));                
end
            
end 




%-------- (12) (-3/(2*dy)) ( dQy H dY1/dx int ( dZx dW/dz ) )^1 -------;


for ii=2:1:Nx

MB(2*Nx*Ny*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Qy(ii)*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)=      MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+p)-     alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQy(ii)*dz/(2*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)-    alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)+ alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+p)+ alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dQy(ii)*dz/(2*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*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*Nz+Nz+p)- alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dz*d2Zyz(ii,2,p); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)+alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*dZy(ii,2,kk) - alfa2*(4/(2*dy))*dQy(ii)*HIC(ii,2)*0.5*dz*d2Zyz(ii,2,kk);                
end

end



%------- (16) (-1/(2*dy)) dQy^1 ( H ( int ( dZz dV/dz ) )^3 -------;


for ii=2:1:Nx

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)-alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZz(ii,3);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+2)+alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZz(ii,3);

end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+2*Nz+1)- alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dZz(ii,3);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,Nx*Ny*Nz+(ii-1)*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3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+1)-   alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)=   MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+p)-   alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQy(ii)*dz/(2*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+Nz+kk)-  alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+1)+ alfa2*(-1/(2*dy))*dQy(ii)*HIC(ii,3)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+3*Nz+p)+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Ny*Nz+(ii-1)*Ny*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,1);
end

end 


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++ The end of Boundary Conditions at the lateral edge Y=Y1 +++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;




%++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++ The lateral edge Y=Y2 (Jy=Ny) +++++++++++;
%++++++++++++++ (free lateral edge) +++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++;



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++ Basic Boundary Conditions at the lateral edge Y=Y2 ++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++ The first equation (basic equation #1) ++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++ KpE Fxx nx ++++++++++++++++++;

%--------------- - Kp1 dU/dx Y2x -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa1*Kp1*(-1/(2*dx))*difY2(ii);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)  -   alfa1*Kp1*(1/(2*dx))*difY2(ii);                                          
end 
end

%-------- i=Nx --------;

for kk=2:1:Nz
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny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ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk-1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk-1)-alfa1*Kp1*(-1/(2*dz))*dZx(ii,Ny,kk)*difY2(ii);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)- alfa1*Kp1*(1/(2*dz))*dZx(ii,Ny,kk)*difY2(ii);                                                          
end 
end

for ii=2:1:Nx
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)- alfa1*Kp1*(1/(2*dz))*dZx(ii,Ny,Nz)*difY2(ii);    
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)-alfa1*Kp1*(-4/(2*dz))*dZx(ii,Ny,Nz)*difY2(ii);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)-   alfa1*Kp1*(3/(2*dz))*dZx(ii,Ny,Nz)*difY2(ii);                                                          
end 


%--------------- - Kp2 dQy dV/dQ Y2x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,N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2*dz))*dZz(ii,Ny)*difY2(ii);                                                          
end 
end

for ii=2:1:Nx
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)- alfa1*Kp2*(1/(2*dz))*dZz(ii,Ny)*difY2(ii);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)-alfa1*Kp2*(-4/(2*dz))*dZz(ii,Ny)*difY2(ii);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)-   alfa1*Kp2*(3/(2*dz))*dZz(ii,Ny)*difY2(ii);                                                          
end 



%++++++++++++++++ KpE Fxy ny +++++++++++++++++;

%---------------- dQy dU/dQ ------------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+ alfa1*(1/(2*dy))*dQy(ii);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa1*(-4/(2*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alfa1*(3/(2*dz))*dZy(ii,Ny,Nz);                                                          
end 


%------------------ dV/dx -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa1*(-1/(2*dx));
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)    + alfa1*(1/(2*dx));                                          
end 
end

%-------- i=Nx --------;

for kk=2:1:Nz
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa1*(1/(2*dx));    
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa1*(-4/(2*dx));
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa1*(3/(2*dx));                                          
end 


%--------------- dQx dV/dQ ---------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB((ii-1)*Ny*Nz+(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ny-1)*Nz+Nz-2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)+ alfa1*(1/(2*dz))*dZx(ii,Ny,Nz);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)+alfa1*(-4/(2*dz))*dZx(ii,Ny,Nz);
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB((ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)+   alfa1*(3/(2*dz))*dZx(ii,Ny,Nz);                                                          
end 



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++ The second equation (basic equation #2) +++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++ KpE Fyx nx +++++++++++++++++++;

%---------------- - dQy dU/dQ Y2x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)- alfa1*(1/(2*dy))*dQy(ii)*difY2(ii);
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk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)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)-   alfa1*(3/(2*dz))*dZx(ii,Ny,Nz)*difY2(ii);                                                          
end 



%+++++++++++++++++ KpE Fyy ny +++++++++++++++++;

%-------------- Kp1 dQy dV/dQ -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+ alfa1*(1/(2*dy))*dQy(ii)*Kp1;
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa1*(-4/(2*dy))*dQy(ii)*Kp1;
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa1*(3/(2*dy))*dQy(ii)*Kp1;                              
end 
end

%-------------- Kp1 dZy dV/dz ----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk-1)=MB(Nx*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end 



%---------------- Kp2 dU/dx -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa1*(-1/(2*dx))*Kp2;
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)    + alfa1*(1/(2*dx))*Kp2;                                          
end 
end

%-------- i=Nx --------;

for kk=2:1:Nz
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa1*(1/(2*dx))*Kp2;
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa1*(-4/(2*dx))*Kp2;
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa1*(3/(2*dx))*Kp2;                                          
end 


%-------------- Kp2 dQx dU/dQ -----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB(N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ny*Nz+(Ny-1)*Nz+kk+1)+ alfa1*(1/(2*dz))*dZz(ii,Ny)*Kp2;                                                          
end 
end

for ii=2:1:Nx
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)+ alfa1*(1/(2*dz))*dZz(ii,Ny)*Kp2;
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)+alfa1*(-4/(2*dz))*dZz(ii,Ny)*Kp2;
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)+   alfa1*(3/(2*dz))*dZz(ii,Ny)*Kp2;                                                          
end 



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++ The third equation (basic equation #3) +++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++ KpE Fzx nx ++++++++++++++++++;

%---------------- - dZz dU/dz Y2x -----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk-1)-alfa1*(-1/(2*dz))*dZz(ii,Ny)*difY2(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)- alfa1*(1/(2*dz))*dZz(ii,Ny)*difY2(ii);                                                          
end 
end

for ii=2:1:Nx
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)- alfa1*(1/(2*dz))*dZz(ii,Ny)*difY2(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)-alfa1*(-4/(2*dz))*dZz(ii,Ny)*difY2(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)-   alfa1*(3/(2*dz))*dZz(ii,Ny)*difY2(ii);                                                          
end 



%----------------- - dW/dx Y2x -----------------;

for ii=2:1:Nx-1
for kk=2:1:Nz                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*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(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)- alfa1*(1/(2*dz))*dZx(ii,Ny,kk)*difY2(ii);                                                          
end 
end

for ii=2:1:Nx
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)- alfa1*(1/(2*dz))*dZx(ii,Ny,Nz)*difY2(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)-alfa1*(-4/(2*dz))*dZx(ii,Ny,Nz)*difY2(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)-   alfa1*(3/(2*dz))*dZx(ii,Ny,Nz)*difY2(ii);                                                          
end 



%++++++++++++++++ KpE Fzy ny +++++++++++++++++;

%----------------- dZz dV/dz ----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(2*Nx*Ny*Nz+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Nz+(Ny-1)*Nz+Nz)+   alfa1*(3/(2*dz))*dZz(ii,Ny);                                                          
end 



%---------------- dQy dW/dQ ----------------;

for ii=2:1:Nx
for kk=2:1:Nz                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+ alfa1*(1/(2*dy))*dQy(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa1*(-4/(2*dy))*dQy(ii);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa1*(3/(2*dy))*dQy(ii);                              
end 
end

%---------------- dZy dW/dz -----------------;

for ii=2:1:Nx
for kk=2:1:Nz-1                                              
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk-1)+alfa1*(-1/(2*dz))*dZy(ii,Ny,kk);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk+1)+ alfa1*(1/(2*dz))*dZy(ii,Ny,kk);                                                          
end 
end

for ii=2:1:Nx
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-2)+ alfa1*(1/(2*dz))*dZy(ii,Ny,Nz);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz-1)+alfa1*(-4/(2*dz))*dZy(ii,Ny,Nz);
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)=  MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)+   alfa1*(3/(2*dz))*dZy(ii,Ny,Nz);                                                          
end 


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++ The end of Basic Boundary Conditions at the lateral edge Y=Y2 ++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++ Boundary Conditions at the lateral edge Y=Y2 ++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%+++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++ The first equation ++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++;


%------------- (1) Kp1 d/dx ( H ( int (dU/dx) ) ----------------;

%--------------- (1,a) Kp1 dH/dx int (dU/dx)  -----------------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+2)-alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)-  alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)-  alfa2*Kp1*dHx(ii,Ny)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+  alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+  alfa2*Kp1*dHx(ii,Ny)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*dHx(ii,Ny)*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*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(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*dHx(Nx,Ny)*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dHx(Nx,Ny)*dz*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*dHx(Nx,Ny)*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*dHx(Nx,Ny)*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dHx(Nx,Ny)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*dHx(Nx,Ny)*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-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*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)-alfa2*Kp1*HIC(ii,Ny)*dz/dx^2;

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*0.5*HIC(ii,Ny)*dz/dx^2;            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*0.5*HIC(ii,Ny)*dz/dx^2;

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*HIC(ii,Ny)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*HIC(ii,Ny)*dz*2/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*Kp1*HIC(ii,Ny)*dz/dx^2;                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*dz/dx^2;         
end
            
end 


%------- i=Nx ------;


MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-4)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=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(2/dx^2);            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(2/dx^2);



for kk=3:1:Nz

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(-1/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dz*(-1/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(-1/dx^2);                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(4/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dz*(4/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(4/dx^2);                

end
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(-5/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dz*(-5/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(-5/dx^2);         
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(2/dx^2);

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dz*(2/dx^2); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*(2/dx^2);         
end





%---------- (2) Kp1 d/dx ( H ( int ( dQx dU/dq ) ) --------------;

%---------- (2,a) Kp1 d/dx ( H dQx ) int ( dU/dq ) --------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(1/(2*dy));                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+2)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(1/(2*dy));

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(-4/(2*dy));                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+2)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(-4/(2*dy));
 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(3/(2*dy));            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*d2QxHx(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*d2QxHx(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*d2QxHx(ii,Ny)*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*d2QxHx(ii,Ny)*dz*(3/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(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((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+   alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(3/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*dQx(ii,Ny)*dz*(4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-3/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-3/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+p)+     alfa2*Kp1*HIC(ii,Ny)*dQx(ii,Ny)*dz*(1/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+kk)+    alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(1/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)+     alfa2*Kp1*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)+    alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+     alfa2*Kp1*HIC(ii,Ny)*dQx(ii,Ny)*dz*(3/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)+    alfa2*Kp1*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(3/(4*dx*dy));                
end

end



%------- i=Nx ------;


MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));                             
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-3)*Nz+2)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-3)*Nz+2)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));
 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3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Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));  
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(3/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(16/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(3/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(9/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(9/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(9/(4*dx*dy));                
end




%---------- (3) Kp1 d/dx ( H ( int ( dZx dU/dz ) ) ----------------;

%------------ (3,a) Kp1 dH/dx int ( dZx dU/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*Kp1*dHx(ii,Ny)*dZx(ii,Ny,1) - alfa2*Kp1*0.5*dHx(ii,Ny)*dz*d2Zxz(ii,Ny,1);                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*dHx(ii,Ny)*dZx(ii,Ny,2) - alfa2*Kp1*0.5*dHx(ii,Ny)*dz*d2Zxz(ii,Ny,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*dHx(ii,Ny)*dZx(ii,Ny,1) - alfa2*Kp1*0.5*dHx(ii,Ny)*dz*d2Zxz(ii,Ny,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*dHx(ii,Ny)*dz*d2Zxz(ii,Ny,p); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*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ii,Ny)*dz*d2Zxz(ii+1,Ny,2)/(2*dx);

end



for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*HIC(ii,Ny)*dZx(ii-1,Ny,1)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,Ny)*dz*d2Zxz(ii-1,Ny,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*dz*d2Zxz(ii-1,Ny,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*Kp1*HIC(ii,Ny)*dZx(ii-1,Ny,kk)/(2*dx) + alfa2*Kp1*0.5*HIC(ii,Ny)*dz*d2Zxz(ii-1,Ny,kk)/(2*dx);                
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*HIC(ii,Ny)*dZx(ii+1,Ny,1)/(2*dx) - alfa2*Kp1*0.5*HIC(ii,Ny)*dz*d2Zxz(ii+1,Ny,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz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1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*HIC(Nx,Ny)*dz*d2Zxz(Nx-2,Ny,p)*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*HIC(Nx,Ny)*dZx(Nx-2,Ny,kk)*(1/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*d2Zxz(Nx-2,Ny,kk)*(1/(2*dx));                
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*HIC(Nx,Ny)*dZx(Nx-1,Ny,1)*(-4/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*d2Zxz(Nx-1,Ny,1)*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*HIC(Nx,Ny)*dz*d2Zxz(Nx-1,Ny,p)*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*HIC(Nx,Ny)*dZx(Nx-1,Ny,kk)*(-4/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*d2Zxz(Nx-1,Ny,kk)*(-4/(2*dx));         
end


for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*HIC(Nx,Ny)*dZx(Nx,Ny,1)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*d2Zxz(Nx,Ny,1)*(3/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*HIC(Nx,Ny)*dz*d2Zxz(Nx,Ny,p)*(3/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*HIC(Nx,Ny)*dZx(Nx,Ny,kk)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,Ny)*dz*d2Zxz(Nx,Ny,kk)*(3/(2*dx));         
end




%---------- (4) Kp2 d/dx ( H ( int ( dQy dV/dq ) ) --------------;

%---------- (4,a) Kp2 d/dx ( H dQy ) int ( dV/dq ) --------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,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3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*0.5*d2QyHx(ii,Ny)*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*d2QyHx(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*d2QyHx(ii,Ny)*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*d2QyHx(ii,Ny)*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*d2QyHx(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*d2QyHx(ii,Ny)*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*d2QyHx(ii,Ny)*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*d2QyHx(ii,Ny)*dz*(3/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*0.5*d2QyHx(ii,Ny)*dz*(3/(2*dy));                
end
            
end 



%---------- (4,b) Kp2 H dQy d/dx ( int ( dV/dq ) ) -------------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny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Ny-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+2)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(3/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(-1/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*dQy(ii)*dz*(-1/(4*dx*dy));  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(-1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*dQy(ii)*dz*(4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*dQy(ii)*dz*(-3/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(-3/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*dQy(ii)*dz*(1/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(1/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(-4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*dQy(ii)*dz*(-4/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*dQy(ii)*dz*(3/(4*dx*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*dQy(ii)*dz*(3/(4*dx*dy));                
end

end



%------- i=Nx ------;


MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,N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Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*dQy(Nx)*dz*(-4/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)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HIC(Nx,Ny)*dQy(Nx)*dz*(-4/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*dQy(Nx)*dz*(16/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*dQy(Nx)*dz*(-12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(-12/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*dQy(Nx)*dz*(3/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*dQy(Nx)*dz*(-12/(4*dx*dy)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(-12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*dQy(Nx)*dz*(9/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ al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ii-2)*Ny*Nz+(Ny-1)*Nz+2)-alfa2*Kp1*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)+    alfa2*Kp1*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+    alfa2*Kp1*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx); 

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*dQx(ii,Ny)*d1Hq(ii,Ny)*dz/(2*dx);  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*Kp1*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*Kp1*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+     alfa2*Kp1*dQx(ii,Ny)*d1Hq(ii,Ny)*dz/(2*dx); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)+    alfa2*Kp1*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);                
end

end 


%------- i=Nx ------;

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*dQx(Nx,Ny)*0.5*d1Hq(Nx,Ny)*dz*(1/(2*dx));                             
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*dQx(Nx,Ny)*0.5*d1Hq(Nx,Ny)*dz*(1/(2*dx));

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+alfa2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1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*d1Hq(Nx,Ny)*dz*(1/(2*dx));                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*d1Hq(Nx,Ny)*dz*(-4/(2*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*d1Hq(Nx,Ny)*dz*(-4/(2*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*d1Hq(Nx,Ny)*dz*(-4/(2*dx));                
end


for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*d1Hq(Nx,Ny)*dz*(3/(2*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*N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nz+2,ii*Ny*Nz+(Ny-2)*Nz+2)+    alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-4/(4*dy*dx));

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)+    alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+    alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-1/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*(-1/(4*dy*dx));  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-1/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*(4/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-3/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*(-3/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-3/(4*dy*dx));                
end


for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+1)=      MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+1)+    alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(1/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+p)=      MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+p)+    alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*(1/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+kk)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+kk)+   alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(1/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)=      MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)+    alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-4/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)=      MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)+    alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*(-4/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)+   alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=      MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+    alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=      MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+    alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*(3/(4*dy*dx)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)+   alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));                
end
            
end 



%------ i=Nx ------;


MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(1/(4*dy*dx));                             
MB((Nx-1)*Ny*Nz+(Ny-1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Ny)*dz*(9/(4*dy*dx));



for kk=3:1:Nz
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(1/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(1/(4*dy*dx));  
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(1/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(-4/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(3/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(3/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(3/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(-4/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-4/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(16/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(16/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(16/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-12/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(-12/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-12/(4*dy*dx));                
end



for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(3/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(3/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(3/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-12/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(-12/(4*dy*dx)); 
end                                            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-12/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(9/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*N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+(Ny-2)*Nz+2)+alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(-4/(2*dy));

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(3/(2*dy));            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(3/(2*dy));

end


for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(1/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*dz*(1/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(1/(2*dy));                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(-4/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*dz*(-4/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(-4/(2*dy));                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(3/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)*d2QxHq(ii,Ny)*dz*(3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*N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x(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-5/dy^2);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+2)+alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-5/dy^2);

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(2/dy^2);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(2/dy^2);

end



for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-1/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*dz*(-1/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-1/dy^2);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(4/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*dz*(4/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(4/dy^2);                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-5/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*dz*(-5/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-5/dy^2);         
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(2/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*dz*(2/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(2/dy^2);         
end

            
end 





%---------- (9) Kp1 dQx d/dq ( H ( int ( dZx dU/dz ) ) ---------------;

%------------ (9,a) Kp1 dQx dH/dq  int ( dZx dU/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*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a2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*d2Zxz(ii,Ny-2,p)*(1/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dZx(ii,Ny-2,kk)*(1/(2*dy)) - alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*0.5*dz*d2Zxz(ii,Ny-2,kk)*(1/(2*dy));                
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)- alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dZx(ii,Ny-1,1)*(-4/(2*dy)) - alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*0.5*dz*d2Zxz(ii,Ny-1,1)*(-4/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)- alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*d2Zxz(ii,Ny-1,p)*(-4/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dZx(ii,Ny-1,kk)*(-4/(2*dy)) - alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*0.5*dz*d2Zxz(ii,Ny-1,kk)*(-4/(2*dy));         
end


for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dZx(ii,Ny,1)*(3/(2*dy)) - alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*d2Zxz(ii,Ny,1)*(3/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dz*d2Zxz(ii,Ny,p)*(3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*dZx(ii,Ny,kk)*(3/(2*dy)) - alfa2*Kp1*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*d2Zxz(ii,Ny,kk)*(3/(2*dy));         
end


end 




%---------- (10) Kp2 dQx d/dq ( H ( int ( dQy dV/dq ) ) --------------;

%----------- (10,a) Kp2 dQx d(dQy H)/dq  int ( dV/dq ) --------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz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alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*0.5*dz*(3/(2*dy));

end



for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*0.5*dz*(1/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*dz*(1/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*0.5*dz*(1/(2*dy));                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*0.5*dz*(-4/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*dz*(-4/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*0.5*dz*(-4/(2*dy));                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*0.5*dz*(3/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*dz*(3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*dQx(ii,Ny)*d2QyHq(ii,Ny)*0.5*dz*(3/(2*dy));         
end
            
end 



%---------- (10,b) Kp2 dQx H dQy  d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ii-1)*Ny*Nz+(Ny-4)*Nz+p)+ alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dQy(ii)*dz*(-1/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)+alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dQy(ii)*0.5*dz*(-1/dy^2);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dQy(ii)*0.5*dz*(4/dy^2);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dQy(ii)*dz*(4/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dQy(ii)*0.5*dz*(4/dy^2);                

end
            

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*N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dQy(ii)*dz*(2/dy^2); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dQy(ii)*0.5*dz*(2/dy^2);         
end

            
end 




%---------- (11) Kp2 dQx d/dq ( H ( int ( dZy dV/dz ) ) ----------------;

%------------ (11,a) Kp2 dQx dH/dq  int ( dZy dV/dz ) ----------------;

for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*Kp2*dQx(ii,Ny)*d1Hq(ii,Ny)*dZy(ii,Ny,1) - alfa2*Kp2*dQx(ii,Ny)*d1Hq(ii,Ny)*0.5*dz*d2Zyz(ii,Ny,1);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp2*dQx(ii,Ny)*d1Hq(ii,Ny)*dZy(ii,Ny,2) - alfa2*Kp2*dQx(ii,Ny)*d1Hq(ii,Ny)*0.5*dz*d2Zyz(ii,Ny,2);

end



for ii=2:1:Nx
                                                      

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny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-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dZy(ii,Ny,1)*(3/(2*dy)) - alfa2*Kp2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*d2Zyz(ii,Ny,1)*(3/(2*dy));

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dz*d2Zyz(ii,Ny,p)*(3/(2*dy)); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*dZy(ii,Ny,kk)*(3/(2*dy)) - alfa2*Kp2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*d2Zyz(ii,Ny,kk)*(3/(2*dy));         
end

end 




%---------- (12) Kp2 dQx d/dq ( H ( int ( dZz dW/dz ) ) ----------------;

%------------- (12,a) Kp2 dQx dH/dq  int ( dZz dW/dz ) ----------------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=  MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*Kp2*dQx(ii,Ny)*d1Hq(ii,Ny)*dZz(ii,Ny);            
MB((ii-1)*Ny*Nz+(Ny-1)*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nz+(Ny-4)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+1)- alfa2*(1/(2*dy))*dQy(ii)^2*HIC(ii,Ny-2)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+p)- alfa2*(1/(2*dy))*dQy(ii)^2*HIC(ii,Ny-2)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)-alfa2*(1/(2*dy))*dQy(ii)^2*HIC(ii,Ny-2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(1/(2*dy))*dQy(ii)^2*HIC(ii,Ny-2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(1/(2*dy))*dQy(ii)^2*HIC(ii,Ny-2)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(1/(2*dy))*dQy(ii)^2*HIC(ii,Ny-2)*0.5*dz/(2*dy);                
end
            
end 




%-------- (14) (1/(2*dy)) dQy^Ny ( H int ( dZy dU/dz ) )^Ny-2 ------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)-alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dZy(ii,Ny-2,1) - alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*0.5*dz*d2Zyz(ii,Ny-2,1);                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-3)*Nz+2)+alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dZy(ii,Ny-2,2) - alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*0.5*dz*d2Zyz(ii,Ny-2,2);


for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dZy(ii,Ny-2,1) - alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*0.5*dz*d2Zyz(ii,Ny-2,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(1/(2*dy))*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ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+2)+    alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)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nx,Ny-2)*dz*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(1/(2*dy))*dQy(Nx)*HIC(Nx,Ny-2)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(1/(2*dy))*dQy(Nx)*HIC(Nx,Ny-2)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(1/(2*dy))*dQy(Nx)*HIC(Nx,Ny-2)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(1/(2*dy))*dQy(Nx)*HIC(Nx,Ny-2)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((Nx-1)*Ny*N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(ii,Ny-2)*0.5*dz/(2*dy);
 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)=  MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+2)=  MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+2)+alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)- alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)- alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)-alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                
end
            
end



%--------- (17) (1/(2*dy)) dQy^Ny ( H int ( dZx dV/dz ) )^Ny-2 ---------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*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nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(-4/(2*dy))*dQy(ii)^2*HIC(ii,Ny-1)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(-4/(2*dy))*dQy(ii)^2*HIC(ii,Ny-1)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(-4/(2*dy))*dQy(ii)^2*HIC(ii,Ny-1)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(ii)^2*HIC(ii,Ny-1)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(-4/(2*dy))*dQy(ii)^2*HIC(ii,Ny-1)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(-4/(2*d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z+(Ny-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+2)+    alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)- alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)- alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)-alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk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C(Nx,Ny-1)*dz*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(-4/(2*dy))*dQy(Nx)*HIC(Nx,Ny-1)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(Nx)*HIC(Nx,Ny-1)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(-4/(2*dy))*dQy(Nx)*HIC(Nx,Ny-1)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(-4/(2*dy))*dQy(Nx)*HIC(Nx,Ny-1)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((Nx-1)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,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);
 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                
end
            
end 




%--------- (22) (-4/(2*dy)) dQy^Ny ( H int ( dZx dV/dz ) )^Ny-1 ---------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)=  MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-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k,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dZx(ii,Ny-1,kk) - alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*0.5*dz*d2Zxz(ii,Ny-1,kk);                
end

end




%--------- (23) (3/(2*dy)) Kp1 ( dQy H dY2/dx int (dU/dx) )^Ny ---------;

for ii=2:1:Nx-1

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+2)-alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)+    alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+    alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+      alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+      alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB((ii-1)*Ny*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Ny-1)*Nz+1)+alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(3/(2*dx));            
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(3/(2*dx));



for kk=3:1:Nz-1

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*dz*(1/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*dz*(-4/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz-1                 

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*dz*(3/(2*dx)); 
end                                            

MB((Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((Nx-1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Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*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3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZx(ii,Ny,1) - alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zxz(ii,Ny,1);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz*d2Zxz(ii,Ny,p); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZx(ii,Ny,kk) - alfa2*(3/(2*dy))*Kp1*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zxz(ii,Ny,kk);                
end

end




%------- (26) (3/(2*dy)) Kp2 ( dQy H dY2/dx int ( dQy dV/dq ) )^Ny -------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*0.5*dz*(1/(2*dy));                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(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ny*Nz+(Ny-3)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*0.5*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*dz*(1/(2*dy));  
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*0.5*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*0.5*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*dz*(-4/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*0.5*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*0.5*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*dz*(3/(2*dy)); 
end                                            
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*Kp2*dQy(ii)^2*HIC(ii,Ny)*difY2(ii)*0.5*dz*(3/(2*dy));                
end
            
end 




%------- (27) (3/(2*dy)) Kp2 ( dQy H dY2/dx int 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(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*(3/(2*dy))*Kp2*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz*d2Zyz(ii,Ny,p); 
end                                            

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*Kp2*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZy(ii,Ny,kk) - alfa2*(3/(2*dy))*Kp2*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zyz(ii,Ny,kk);                
end

end




%------- (28) (3/(2*dy)) Kp2 ( dQy H dY1/dx ( int ( dZz dW/dz ) )^Ny -------;


for ii=2:1:Nx

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*(3/(2*dy))*Kp2*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZz(ii,Ny);                             
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(3/(2*dy))*Kp2*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZz(ii,Ny);

end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk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ii-1)*Ny*Nz+(Ny-1)*Nz+Nz)-   alfa2*dZx(ii,Ny,Nz)*(3/(2*dz)); 
end 



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ + KpE dens Freq^2 U +++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

for ii=2:1:Nx 
    
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);

end 



for ii=2:1:Nx 
    
for kk=3:1:Nz 
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(ii,Ny);  
end

MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);
end

end 



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ The second equation +++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%------------- (1) Kp1 d/dx ( H dY2/dx ( int (dU/dx) ) ----------------;

%--------------- (1,a) Kp1 d(H dY1/dx)/dx int (dU/dx)  ----------------;

for ii=2:1:Nx-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*Kp1*0.5*d2Y2xHx(ii,Ny)*dz/(2*dx);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-2)*Ny*Nz+(Ny-1)*Nz+2)-alfa2*Kp1*0.5*d2Y2xHx(ii,Ny)*dz/(2*dx);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)+    alfa2*Kp1*0.5*d2Y2xHx(ii,Ny)*dz/(2*dx);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+    alfa2*Kp1*0.5*d2Y2xHx(ii,Ny)*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*0.5*d2Y2xHx(ii,Ny)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*d2Y2xHx(ii,Ny)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*Kp1*0.5*d2Y2xHx(ii,Ny)*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+      alfa2*Kp1*0.5*d2Y2xHx(ii,Ny)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+      alfa2*Kp1*d2Y2xHx(ii,Ny)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*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x-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*d2Y2xHx(Nx,Ny)*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*d2Y2xHx(Nx,Ny)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*d2Y2xHx(Nx,Ny)*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*d2Y2xHx(Nx,Ny)*dz*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*d2Y2xHx(Nx,Ny)*dz*(3/(2*dx)); 
end                                            

MB(Nx*Ny*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z+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+1)+    alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dz/dx^2;            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-1)*Nz+2)+    alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dz/dx^2;

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dz*2/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dz/dx^2;                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+      alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+      alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz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ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dz*(-1/dx^2); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-4)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*(-1/dx^2);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*(4/dx^2);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dz*(4/dx^2); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*(4/dx^2);                

end
            

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*(-5/dx^2);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dz*(-5/dx^2); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*(-5/dx^2);         
end


for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*(2/dx^2);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(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)*Ny*Nz+(Ny-2)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+2)+alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(-4/(2*dy));
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(3/(2*dy));            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*d2QxHY2x(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*d2QxHY2x(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*d2QxHY2x(ii,Ny)*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny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x*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-3/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+p)+     alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+kk)+    alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(1/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)+     alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)+    alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)+     alfa2*Kp1*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+kk)+    alfa2*Kp1*0.5*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(3/(4*dx*dy));                
end

end



%------- i=Nx ------;


MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(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x-3)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(16/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(3/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(9/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(9/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dQx(Nx,Ny)*dz*(9/(4*dx*dy));                
end




%-------- (3) Kp1 d/dx ( H dY2/dx ( int ( dZx dU/dz ) ) -----------;

%--------- (3,a) Kp1 d(H dY2/dx)/dx  int ( dZx dU/dz ) ------------;


for ii=2:1:Nx

MB(Nx*Ny*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a2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*d2Zxz(Nx-1,Ny,kk)*(-4/(2*dx));         
end


for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dZx(Nx,Ny,1)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*d2Zxz(Nx,Ny,1)*(3/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dz*d2Zxz(Nx,Ny,p)*(3/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp1*HIC(Nx,Ny)*difY2(Nx)*dZx(Nx,Ny,kk)*(3/(2*dx)) - alfa2*Kp1*0.5*HIC(Nx,Ny)*difY2(Nx)*dz*d2Zxz(Nx,Ny,kk)*(3/(2*dx));         
end




%--------- (4) Kp2 d/dx ( H dY2/dx ( int ( dQy dV/dq ) ) ------------;

%--------- (4,a) Kp2 d/dx ( H dY2/dx dQy ) int ( dV/dq ) ------------;

for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*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p2*0.5*d2QyHY2x(ii,Ny)*dz*(3/(2*dy));            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*Kp2*0.5*d2QyHY2x(ii,Ny)*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*0.5*d2QyHY2x(ii,Ny)*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*d2QyHY2x(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*d2QyHY2x(ii,Ny)*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*d2QyHY2x(ii,Ny)*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*d2QyHY2x(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*d2QyHY2x(ii,Ny)*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*d2QyHY2x(ii,Ny)*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(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z+2)+    alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(3/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-1/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-1/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-3/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-3/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)+     alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)+     alfa2*Kp2*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(1/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)+    alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(1/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)+     alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)+     alfa2*Kp2*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)+    alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*Kp2*0.5*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)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*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(1/(4*dx*dy));  
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny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z+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-4/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-4/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(16/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*Kp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5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*Kp2*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-12/(4*dx*dy)); 
end                                            
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(-12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*Kp2*0.5*HIC(Nx,Ny)*difY2(Nx)*dQy(Nx)*dz*(9/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*Kp2*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*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)- alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                
end
            
end 




%-------- (8) (1/(2*dy)) dQx^Ny ( H int ( dZy dU/dz ) )^Ny-2 ------;


for ii=2:1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/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*0.5*dz/(2*dx);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+2)+    alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3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(Ny-2)*Nz+1)+alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+2)+alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)- alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)- alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)-alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(1/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                
end
            
end



%--------- (11) (1/(2*dy)) dQx^Ny ( H int ( dZx dV/dz ) )^Ny-2 ---------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=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ny)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                
end
            
end 



%-------- (13) (-4/(2*dy)) dQx^Ny ( H int ( dZy dU/dz ) )^Ny-1 ------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)-alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dZy(ii,Ny-1,1) - alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*0.5*dz*d2Zyz(ii,Ny-1,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*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-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)- alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)- alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)-alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(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ny)*HIC(Nx,Ny-1)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(-4/(2*dy))*dQx(Nx,Ny)*HIC(Nx,Ny-1)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(-4/(2*dy))*dQx(Nx,Ny)*HIC(Nx,Ny-1)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(-4/(2*dy))*dQx(Nx,Ny)*HIC(Nx,Ny-1)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(-4/(2*dy))*dQx(Nx,Ny)*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1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                
end
            
end 



%--------- (16) (-4/(2*dy)) dQx^Ny ( H int ( dZx dV/dz ) )^Ny-1 ---------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)=  MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)-alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*dZx(ii,Ny-1,1) - alfa2*(-4/(2*dy))*dQx(ii,Ny)*HIC(ii,Ny-1)*0.5*dz*d2Zxz(ii,Ny-1,1);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(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:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*N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x-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*difY2(Nx)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQx(Nx,Ny)*HIC(Nx,Ny)*difY2(Nx)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*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-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*Kp1*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*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*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(3/(2*dy));            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(1/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+  alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+  alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+ alfa2*(3/(2*dy))*Kp2*dQx(ii,Ny)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*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*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+2)+alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)- alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)- alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)-alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(1/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                
end
            
end 



%-------- (24) (1/(2*dy)) Kp1 dQy^Ny ( H int ( dZy dV/dz ) )^Ny-2 ------;


for ii=2:1:Nx

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-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1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*0.5*dz/(2*dx);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-3)*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,ii*Ny*Nz+(Ny-3)*Nz+2)+    alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*0.5*dz/(2*dx);

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-3)*Nz+1)=     MB(Nx*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,Ny-2)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-2)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-2)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-2)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(1/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-2)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-3)*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:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+p)- alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*dQx(ii,Ny-2)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)-alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*dQx(ii,Ny-2)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(1/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-2)*dQx(ii,Ny-2)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*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ny-3)*Nz+p)- alfa2*(-4/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-1)*dQy(ii)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(-4/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(-4/(2*dy))*dQy(ii)*Kp1*HIC(ii,Ny-1)*dQy(ii)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa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)*Ny*Nz+(Ny-1)*Nz+kk,(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)-alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,ii*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*0.5*dz/(2*dx);         
end
            
end 


%--- i=Nx ---;

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+2,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+alfa2*(-4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-1)*0.5*dz*(1/(2*dx));                             
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz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ny-1)*0.5*dz*(3/(2*dx));



for kk=3:1:Nz

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-1)*0.5*dz*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(-4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-1)*dz*(1/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(-4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-1)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(Nx)*Kp2*HIC(Nx,Ny-1)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,(Nx-2)*Ny*Nz+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Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*dQx(ii,Ny-1)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(ii)*Kp2*HIC(ii,Ny-1)*dQx(ii,Ny-1)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*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*Nz+2) = MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+2) + alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(1/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(-4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*0.5*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQy(ii)*dz*(3/(2*dy)); 
end                                            
M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ii,Ny)*difY2(ii)*dZy(ii,Ny,1) - alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zyz(ii,Ny,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz*d2Zyz(ii,Ny,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZy(ii,Ny,kk) - alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zyz(ii,Ny,kk);                
end

end



%--------- (37) (3/(2*dy)) ( dQy H dY2/dx int (dV/dx) )^Ny  ----------;

for ii=2:1:Nx-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)-alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+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*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)+     alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)+    alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB(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Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(Nx,Ny)*difY2(Nx)*dz*(-4/(2*dx)); 
end                                            

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(-4/(2*dx));                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB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ii-1)*Ny*Nz+(Ny-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-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ii)*HIC(ii,Ny)*difY2(ii)*dZx(ii,Ny,2) - alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zxz(ii,Ny,2);


for kk=3:1:Nz

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZx(ii,Ny,1) - alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zxz(ii,Ny,1);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz*d2Zxz(ii,Ny,p); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dZx(ii,Ny,kk) - alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz*d2Zxz(ii,Ny,kk);                
end

end



%------------------ (40) Kp1 H dY2/dx dZ/dx dU/dx  --------------------;

for ii=2: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Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);

end 



for ii=2:1:Nx 

    
for kk=3:1:Nz 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1) + alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(ii,Ny);  
end

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);
end

end 



%+++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ The third equation +++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) d/dx ( H ( int ( dZz dU/dz ) ) ----------------;

%----------- (1,a) dH/dx ( int ( dZz dU/dz ) ) ----------------;

for ii=2:1:Nx

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,(ii-1)*Ny*Nz+(Ny-1)*Nz+1)=MB(2*Nx*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end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*0.5*dHx(ii,Ny)*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*0.5*dHx(ii,Ny)*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*dHx(ii,Ny)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*0.5*dHx(ii,Ny)*dz/(2*dx);         
end
            
end 



%--- i=Nx ---;

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*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+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*0.5*HIC(ii,Ny)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)- alfa2*HIC(ii,Ny)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*HIC(ii,Ny)*dz*2/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*HIC(ii,Ny)*dz/dx^2;                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+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1)*Nz+p)+ alfa2*HIC(Nx,Ny)*dz*(-5/dx^2); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*0.5*HIC(Nx,Ny)*dz*(-5/dx^2);         
end


for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*0.5*HIC(Nx,Ny)*dz*(2/dx^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*HIC(Nx,Ny)*dz*(2/dx^2); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*0.5*HIC(Nx,Ny)*dz*(2/dx^2);         
end




%------------- (3) d/dx ( H ( int ( dQx dW/dq ) ) --------------;

%------------- (3,a) d/dx (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ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*0.5*d2QxHx(ii,Ny)*dz*(3/(2*dy));            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*0.5*d2QxHx(ii,Ny)*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*0.5*d2QxHx(ii,Ny)*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*d2QxHx(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*0.5*d2QxHx(ii,Ny)*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*0.5*d2QxHx(ii,Ny)*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*d2QxHx(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*0.5*d2QxHx(ii,Ny)*dz*(-4/(2*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*0.5*d2QxHx(ii,Ny)*dz*(3/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk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-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+2)+    alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(3/(4*dx*dy));
 
end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*HIC(ii,Ny)*dQx(ii,Ny)*dz*(4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-3/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-3/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-3/(4*dx*dy));                
end



for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)+     alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(1/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)+     alfa2*HIC(ii,Ny)*dQx(ii,Ny)*dz*(1/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)+    alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(1/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)+     alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-4/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)+     alfa2*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)+    alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(-4/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*0.5*HIC(ii,Ny)*dQx(ii,Ny)*dz*(3/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)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x-3)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));  
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(1/(4*dx*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*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.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-4/(4*dx*dy));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(16/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(16/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(16/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*d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dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(-12/(4*dx*dy));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*0.5*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(9/(4*dx*dy));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*HIC(Nx,Ny)*dQx(Nx,Ny)*dz*(9/(4*dx*dy)); 
end                                            
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Hq(ii,Ny)*dz/(2*dx);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*dQx(ii,Ny)*d1Hq(ii,Ny)*dz/(2*dx);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*dQx(ii,Ny)*0.5*d1Hq(ii,Ny)*dz/(2*dx);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)+     alfa2*dQx(ii,Ny)*d1Hq(ii,Ny)*dz/(2*dx); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz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    alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-4/(4*dy*dx));

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+    alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+2)+    alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));

end


for ii=2:1:Nx-1
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-1/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*dQx(ii,Ny)*HIC(ii,Ny)*dz*(-1/(4*dy*dx));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-1/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*dQx(ii,Ny)*HIC(ii,Ny)*dz*(4/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-3/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*dQx(ii,Ny)*HIC(ii,Ny)*dz*(-3/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-3/(4*dy*dx));                
end


for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+1)+     alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(1/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+p)+     alfa2*dQx(ii,Ny)*HIC(ii,Ny)*dz*(1/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-3)*Nz+kk)+    alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(1/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+1)+     alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-4/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+p)+     alfa2*dQx(ii,Ny)*HIC(ii,Ny)*dz*(-4/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-2)*Nz+kk)+    alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(-4/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)+     alfa2*dQx(ii,Ny)*HIC(ii,Ny)*dz*(3/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+kk)+    alfa2*dQx(ii,Ny)*0.5*HIC(ii,Ny)*dz*(3/(4*dy*dx));                
end
            
end 



%------ i=Nx ------;


MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)+alfa2*dQx(Nx,Ny)*0.5*HI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-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(1/(4*dy*dx));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(1/(4*dy*dx));  
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(1/(4*dy*dx));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-4/(4*dy*dx));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*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(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(16/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(16/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(16/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-12/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*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nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(3/(4*dy*dx));                
end
            
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-12/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(-12/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(-12/(4*dy*dx));                
end

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(9/(4*dy*dx));                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*dQx(Nx,Ny)*HIC(Nx,Ny)*dz*(9/(4*dy*dx)); 
end                                            
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*dQx(Nx,Ny)*0.5*HIC(Nx,Ny)*dz*(9/(4*dy*dx));                
end




%---------- (7) dQx d/dq ( H ( int ( dQx dW/dq ) ) --------------;

%----------- (7,a) dQx d(H dQx)/dq  int ( dW/dq ) --------------;

for ii=2:1:Nx

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(1/(2*dy));                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)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*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(3/(2*dy));

end


for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(1/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*dz*(1/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(1/(2*dy));                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(-4/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*dz*(-4/(2*dy)); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+kk)+alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(-4/(2*dy));                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*0.5*dz*(3/(2*dy));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*dQx(ii,Ny)*d2QxHq(ii,Ny)*dz*(3/(2*dy)); 
end                                            

MB(2*Nx*Ny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ny-1)*Nz+2)+alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(2/dy^2);

end



for ii=2:1:Nx

                                                      
for kk=3:1:Nz

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)+ alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-1/dy^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)+ alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*dz*(-1/dy^2); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)+alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-1/dy^2);                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(4/dy^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*dz*(4/dy^2); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(4/dy^2);                

end
            

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*0.5*dz*(-5/dy^2);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*dQx(ii,Ny)^2*HIC(ii,Ny)*dz*(-5/dy^2); 
end                                            

MB(2*Nx*Ny*N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-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+1)- alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+p)- alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQy(ii)*dz/(2*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-4)*Nz+kk)-alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(1/(2*dy))*dQy(ii)*HIC(ii,Ny-2)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*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nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)- alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)- alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQy(ii)*dz/(2*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)-alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                
end
                                                                           

for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(-4/(2*dy))*dQy(ii)*HIC(ii,Ny-1)*dQy(ii)*0.5*dz/(2*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*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ny-1)*Nz+1)- alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+p)- alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dz/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(Ny-1)*Nz+kk)-alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);                
end
                                                                           

for kk=3:1:Nz                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+1)+     alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*0.5*dz/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(Ny-1)*Nz+p)+     alfa2*(3/(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*(1/(2*dx));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*dz*(1/(2*dx)); 
end                                            

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-3)*Ny*Nz+(Ny-1)*Nz+kk)+alfa2*(3/(2*dy))*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(1/(2*dx));                
end
                                                                           

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+1)+ alfa2*(3/(2*dy))*dQy(Nx)*HIC(Nx,Ny)*difY2(Nx)*0.5*dz*(-4/(2*dx));

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(Nx-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(Nx-2)*Ny*Nz+(Ny-1)*Nz+p)+ alfa2*(3/(2*dy))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-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+2)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));
 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1) = MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+1)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2) = MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+2)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(3/(2*dy));
 
end


for ii=2:1:Nx
                                                      
for kk=3:1:Nz
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(1/(2*dy));  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-3)*Nz+kk)+alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(1/(2*dy));                
end
                                                                           
for kk=3:1:Nz                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+1)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*0.5*dz*(-4/(2*dy));                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-2)*Nz+p)+ alfa2*(3/(2*dy))*dQy(ii)*HIC(ii,Ny)*difY2(ii)*dQx(ii,Ny)*dz*(-4/(2*dy)); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(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nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+p) + alfa2*KpE*dens*Freq^2*dz*HIC(ii,Ny);  
end

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(Ny-1)*Nz+kk)+ alfa2*KpE*0.5*dens*Freq^2*dz*HIC(ii,Ny);
end

end 


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++ The end of Boundary Conditions at the lateral edge Y=Y2 ++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;




%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++ Ice Shelf Surface (k=1) +++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++ The first equation ++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%--------------------- Kp1 H dZ/dx dU/dx ---------------------;

for ii=2:1:Nx-1 
for jj=1:1:Ny
MB((ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp1*HIC(ii,jj)*dZx(ii,jj,1)*(-1/(2*dx)); 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+1,ii*Ny*Nz+(jj-1)*Nz+1)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+1,ii*Ny*Nz+(jj-1)*Nz+1)+    Kp1*H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z+(jj-1)*Nz+3)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+3)-dZy(ii,jj,1)*(-1/(2*dz));
end 
end



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++ The third equation ++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%------------------- H dZ/dx dZ/dz dU/dz -----------------;

for ii=2:1:Nx 
for jj=1:1:Ny
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-1)*Ny*Nz+(jj-1)*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-1)*Ny*Nz+(jj-1)*Nz+1)+HIC(ii,jj)*dZx(ii,jj,1)*dZz(ii,jj)*(-3/(2*dz)); 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-1)*Ny*Nz+(jj-1)*Nz+2)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-1)*Ny*Nz+(jj-1)*Nz+2)+HIC(ii,jj)*dZx(ii,jj,1)*dZz(ii,jj)*(4/(2*dz));
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-1)*Ny*Nz+(jj-1)*Nz+3)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,(ii-1)*Ny*Nz+(jj-1)*Nz+3)+HIC(ii,jj)*dZx(ii,jj,1)*dZz(ii,jj)*(-1/(2*dz));
end 
end


%--------------------- H dZ/dx dW/dx  ---------------------;

for ii=2:1:Nx-1 
for jj=1:1:Ny
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB(2*Nx*Ny*Nz+(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ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2)-Kp2*dZy(ii,jj,1)*(4/(2*dz)); 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+3)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+3)-Kp2*dZy(ii,jj,1)*(-1/(2*dz)); 
end 
end





%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++ Ice-shelf base (k=Nz) +++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++ The first equation ++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

%---------- (1) Kp1 d/dx ( H ( int (dU/dx) ) ----------------;

%---------- (1,a) Kp1 H d/dx ( int (dU/dx) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp1*0.5*HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)+Kp1*HIC(ii,jj)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)+Kp1*0.5*HIC(ii,jj)*dz/dx^2;                

                                                                           

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-Kp1*2*HIC(ii,jj)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-Kp1*HIC(ii,jj)*dz/dx^2;                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)+Kp1*0.5*HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)+Kp1*HIC(ii,jj)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)+Kp1*0.5*HIC(ii,jj)*dz/dx^2;         
            
end 
end




%---------- (1,b) Kp1 dH/dx ( int (dU/dx) ) ---------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)-Kp1*0.5*d1Hx(ii,jj)*dz/(2*dx);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)-Kp1*d1Hx(ii,jj)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-Kp1*0.5*d1Hx(ii,jj)*dz/(2*dx);                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)+Kp1*0.5*d1Hx(ii,jj)*dz/(2*dx);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)+Kp1*d1Hx(ii,jj)*dz/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)+Kp1*0.5*d1Hx(ii,jj)*dz/(2*dx);         
            
end 
end




%---------- (2) Kp1 d/dx ( H ( int ( dQx dU/dq ) ) ----------------;

%---------- (2,a) Kp1 H dQx d/dx ( int ( dU/dq ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp1*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                

                                                                           
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)- Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)- Kp1*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)-Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)- Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)- Kp1*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)-Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                

            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)+ Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)+ Kp1*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)+Kp1*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                
            
end 
end




%---------- (2,b) Kp1 d/dx (H dQx) int ( dU/dq ) ----------------;


%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)- Kp1*0.5*d2QxHx(ii,jj)*dz/(2*dy);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)- Kp1*d2QxHx(ii,jj)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp1*0.5*d2QxHx(ii,jj)*dz/(2*dy);                

                                                                           
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+ Kp1*0.5*d2QxHx(ii,jj)*dz/(2*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+ Kp1*d2QxHx(ii,jj)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp1*0.5*d2QxHx(ii,jj)*dz/(2*dy);                
         
end 
end




%---------- (3) Kp1 d/dx ( H ( int ( dZx dU/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp1*HIC(ii-1,jj)*dZx(ii-1,jj,1)/(2*dx) + Kp1*0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)+Kp1*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-Kp1*HIC(ii-1,jj)*dZx(ii-1,jj,Nz)/(2*dx) + Kp1*0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,Nz)/(2*dx);                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)-Kp1*HIC(ii+1,jj)*dZx(ii+1,jj,1)/(2*dx) - Kp1*0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)-Kp1*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)+Kp1*HIC(ii+1,jj)*dZx(ii+1,jj,Nz)/(2*dx) - Kp1*0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,Nz)/(2*dx);         
            
end 
end



%---------- (4) Kp2 d/dx ( H ( int ( dQy dV/dq ) ) ----------------;

%--------- (4,a) Kp2 H dQy d/dx ( int (  dV/dq ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp2*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                

                                                                           
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- Kp2*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)-Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- Kp2*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)-Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                

            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)=         MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)=         MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ Kp2*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)=        MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)+Kp2*0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                
            
end 
end




%--------- (4,b) Kp2 d/dx ( H dQy ) int ( dV/dq ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)- Kp2*0.5*d2QyHx(ii,jj)*dz/(2*dy);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)- Kp2*d2QyHx(ii,jj)*dz/(2*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp2*0.5*d2QyHx(ii,jj)*dz/(2*dy);                

                                                                           
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+ Kp2*0.5*d2QyHx(ii,jj)*dz/(2*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+ Kp2*d2QyHx(ii,jj)*dz/(2*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp2*0.5*d2QyHx(ii,jj)*dz/(2*dy);                
     
end 
end




%---------- (5) Kp2 d/dx ( H ( int ( dZy dV/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp2*HIC(ii-1,jj)*dZy(ii-1,jj,1)/(2*dx) + Kp2*0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+Kp2*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-Kp2*HIC(ii-1,jj)*dZy(ii-1,jj,Nz)/(2*dx) + Kp2*0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,Nz)/(2*dx);                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)-Kp2*HIC(ii+1,jj)*dZy(ii+1,jj,1)/(2*dx) - Kp2*0.5*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)=     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+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+Kp2*HIC(ii+1,jj)*dZz(ii+1,jj)/(2*dx);

end 
end




%---------- (7) Kp1 dQx d/dq ( H ( int ( dU/dx ) ) ----------------;

%---------- (7,a) Kp1 dQx H d/dq ( int ( dU/dx ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp1*dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)- Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)- Kp1*dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)-Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
                                                                           

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)- Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)- Kp1*dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)-Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                

            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)+ Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)+ Kp1*dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)+Kp1*dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
            
end 
end




%---------- (7,b) Kp1 dQx dH/dq int ( dU/dx ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)- Kp1*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)- Kp1*dQx(ii,jj)*d1Hq(ii,jj)*dz/(2*dx);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-Kp1*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)+ Kp1*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)+ Kp1*dQx(ii,jj)*d1Hq(ii,jj)*dz/(2*dx); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)+Kp1*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                

end 
end



%---------- (8) Kp1 dQx d/dq ( H ( int ( dQx dU/dq ) ) --------------;

%--------- (8,a) Kp1 dQx H dQx d/dq ( int ( dU/dq ) ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+Kp1*dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;                
                                                                           


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*Kp1*dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-Kp1*dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2;                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+Kp1*dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+Kp1*dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp1*dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;         
            
end 
end




%---------- (8,b) Kp1 dQx d/dq ( H dQx ) int ( dU/dq ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)-Kp1*dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)-Kp1*dQx(ii,jj)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp1*dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);                
                                                                           


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+Kp1*dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+Kp1*dQx(ii,jj)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp1*dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (9) Kp1 dQx d/dq ( H ( int ( dZx dU/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,Nz)/(2*dy) + Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,Nz)/(2*dy);                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)-Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)-Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,Nz)/(2*dy) - Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,Nz)/(2*dy);         
            
end 
end




%---------- (10) Kp2 dQx d/dq ( H ( int ( dQy dV/dq ) ) --------------;

%--------- (10,a) Kp2 dQx H dQy d/dq ( int ( dV/dq ) ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                    
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp2*dQx(ii,jj)*0.5*HIC(ii,jj)*dQy(ii)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp2*dQx(ii,jj)*HIC(ii,jj)*dQy(ii)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+Kp2*dQx(ii,jj)*0.5*HIC(ii,jj)*dQy(ii)*dz/dy^2;                
                                                                           


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp2*dQx(ii,jj)*HIC(ii,jj)*dQy(ii)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*Kp2*dQx(ii,jj)*HIC(ii,jj)*dQy(ii)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-Kp2*dQx(ii,jj)*HIC(ii,jj)*dQy(ii)*dz/dy^2;                

          

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+Kp2*dQx(ii,jj)*0.5*HIC(ii,jj)*dQy(ii)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+Kp2*dQx(ii,jj)*HIC(ii,jj)*dQy(ii)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp2*dQx(ii,jj)*0.5*HIC(ii,jj)*dQy(ii)*dz/dy^2;         
            
end 
end




%---------- (10,b) Kp2 dQx dH/dq dQy int ( dV/dq ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                    
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)-Kp2*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dQy(ii)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)-Kp2*dQx(ii,jj)*d1Hq(ii,jj)*dQy(ii)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp2*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dQy(ii)*dz/(2*dy);                
                                                                           
     

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+Kp2*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dQy(ii)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+Kp2*dQx(ii,jj)*d1Hq(ii,jj)*dQy(ii)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp2*dQx(ii,jj)*0.5*d1Hq(ii,jj)*dQy(ii)*dz/(2*dy);         
            
end 
end




%---------- (11) Kp2 dQx d/dq ( H ( int ( dZy dV/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp2*dQx(ii,jj)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + Kp2*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*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C(ii,jj+1)*dZz(ii,jj+1)/(2*dy);
          
end 
end




%---------- (13) dQy d/dq ( H ( int ( dQy dU/dq ) ) --------------;

%--------- (13,a) dQy H dQy d/dq ( int ( dU/dq ) ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;                
                                                                           


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQy(ii)^2*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-dQy(ii)^2*HIC(ii,jj)*dz/dy^2;                

            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;         
            
end 
end




%---------- (13,b) dQy dH/dq dQy int ( dU/dq ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)-dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)-dQy(ii)^2*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);                
                                                                           


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+dQy(ii)^2*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (14) dQy d/dq ( H ( int ( dZy dU/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                     
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,Nz)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,Nz)/(2*dy);                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)-dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)-dQy(ii)*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,Nz)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,Nz)/(2*dy);         
            
end 
end




%---------- (15) dQy d/dq ( H ( int ( dV/dx ) ) ----------------;

%---------- (15,a) dQy H d/dq ( int ( dV/dx ) ) ----------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)-dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                

                                                                           
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)-dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)=         MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)=         MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)=        MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)+dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
            
end 
end



%---------- (15,b) dQy dH/dq  int ( dV/dx ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)- dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                                                         
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)- dQy(ii)*d1Hq(ii,jj)*dz/(2*dx);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)+ dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                     
for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)+ dQy(ii)*d1Hq(ii,jj)*dz/(2*dx); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                

end 
end



%---------- (16) dQy d/dq ( H ( int ( dQx dV/dq ) ) --------------;

%---------- (16,a) dQy H dQx d/dq ( int ( dV/dq ) ) --------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;                
                                                                           


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;                



MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;         
            
end 
end




%---------- (16,b) dQy d/dq ( H dQx ) int ( dV/dq ) ------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)-dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)-dQy(ii)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);                
                                                                           


MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)=     MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+dQy(ii)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (17) dQy d/dq ( H ( int ( dZx dV/dz ) ) ----------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*N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ii-1)*Ny+jj)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj) - KpE*dHbx(ii,jj);                                                          
end 
end




%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ + KpE dens Freq^2 U +++++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for ii=2:1:Nx-1 
for jj=2:1:Ny-1
    
MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

for p=2:1:Nz-1                                                         
 MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p) + KpE*dens*Freq^2*dz*HIC(ii,jj);  
end

MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)+ KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

end
end 



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++ The second equation +++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%------------ (1) d/dx ( H ( int ( dQy dU/dq ) ) ----------------;

%------------ (1,a) H dQy d/dx ( int ( dU/dq ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ 0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                

                                                                           
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)- 0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)- HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)-0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)- 0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)- HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)-0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                

            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)+ 0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)+ HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)+0.5*HIC(ii,jj)*dQy(ii)*dz/(4*dx*dy);                
            
end 
end




%---------- (1,b) d/dx (H dQy) int ( dU/dq ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)- 0.5*d2QyHx(ii,jj)*dz/(2*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)- d2QyHx(ii,jj)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-0.5*d2QyHx(ii,jj)*dz/(2*dy);                

                                                                           
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+ 0.5*d2QyHx(ii,jj)*dz/(2*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+ d2QyHx(ii,jj)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+0.5*d2QyHx(ii,jj)*dz/(2*dy);                
         
end 
end



%---------- (2) d/dx ( H ( int ( dZy dU/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+HIC(ii-1,jj)*dZy(ii-1,jj,1)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-HIC(ii-1,jj)*dZy(ii-1,jj,Nz)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,Nz)/(2*dx);                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)-HIC(ii+1,jj)*dZy(ii+1,jj,1)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)-HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)+HIC(ii+1,jj)*dZy(ii+1,jj,Nz)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,Nz)/(2*dx);         
            
end 
end




%---------- (3) d/dx ( H ( int (dV/dx) ) ----------------;

%---------- (3,a) H d/dx ( int (dV/dx) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+0.5*HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii,jj)*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)+0.5*HIC(ii,jj)*dz/dx^2;                

                                                                           

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*HIC(ii,jj)*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-HIC(ii,jj)*dz/dx^2;                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)+0.5*HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)+HIC(ii,jj)*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+0.5*HIC(ii,jj)*dz/dx^2;         
            
end 
end




%---------- (3,b) dH/dx ( int (dU/dx) ) ---------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)-0.5*d1Hx(ii,jj)*dz/(2*dx);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)-d1Hx(ii,jj)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-0.5*d1Hx(ii,jj)*dz/(2*dx);                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)+0.5*d1Hx(ii,jj)*dz/(2*dx);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)+d1Hx(ii,jj)*dz/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+0.5*d1Hx(ii,jj)*dz/(2*dx);         
            
end 
end




%---------- (4) d/dx ( H ( int ( dQx dV/dq ) ) ----------------;

%---------- (4,a) H dQx d/dx ( int ( dV/dq ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                

                                                                           
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)-0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)-0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                

            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)+0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                
            
end 
end



%---------- (4,b) d/dx (H dQx) int ( dV/dq ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)- 0.5*d2QxHx(ii,jj)*dz/(2*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)- d2QxHx(ii,jj)*dz/(2*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-0.5*d2QxHx(ii,jj)*dz/(2*dy);                

                                                                           
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+ 0.5*d2QxHx(ii,jj)*dz/(2*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+ d2QxHx(ii,jj)*dz/(2*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+0.5*d2QxHx(ii,jj)*dz/(2*dy);                
         
end 
end




%---------- (5) d/dx ( H ( int ( dZx dV/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+HIC(ii-1,jj)*dZx(ii-1,jj,1)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-HIC(ii-1,jj)*dZx(ii-1,jj,Nz)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,Nz)/(2*dx);                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)-HIC(ii+1,jj)*dZx(ii+1,jj,1)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)-HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+HIC(ii+1,jj)*dZx(ii+1,jj,Nz)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,Nz)/(2*dx);         
            
end 
end




%---------- (6) dQx d/dq ( H ( int ( dQy dU/dq ) ) --------------;

%--------- (6,a) dQx H dQy d/dq ( int ( dU/dq ) ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)*dQy(ii)*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)*dQy(ii)*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+dQx(ii,jj)*dQy(ii)*0.5*HIC(ii,jj)*dz/dy^2;                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQx(ii,jj)*dQy(ii)*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*dQx(ii,jj)*dQy(ii)*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-dQx(ii,jj)*dQy(ii)*HIC(ii,jj)*dz/dy^2;                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+dQx(ii,jj)*dQy(ii)*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+dQx(ii,jj)*dQy(ii)*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*dQy(ii)*0.5*HIC(ii,jj)*dz/dy^2;         
            
end 
end




%---------- (6,b) dQx dH/dq dQy int ( dU/dq ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)-dQx(ii,jj)*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)-dQx(ii,jj)*dQy(ii)*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dy);                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+dQx(ii,jj)*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+dQx(ii,jj)*dQy(ii)*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (7) dQx d/dq ( H ( int ( dZy dU/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*HIC(ii,jj-1)*dZy(ii,jj-1,Nz)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,Nz)/(2*dy);                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)-dQx(ii,jj)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)-dQx(ii,jj)*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*HIC(ii,jj+1)*dZy(ii,jj+1,Nz)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,Nz)/(2*dy);         
            
end 
end




%---------- (8) dQx d/dq ( H ( int ( dV/dx ) ) ----------------;

%---------- (8,a) dQx H d/dq ( int ( dV/dx ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
                                                                           

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)-dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                

            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
            
end 
end




%---------- (8,b) dQx dH/dq int ( dV/dx ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)- dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)- dQx(ii,jj)*d1Hq(ii,jj)*dz/(2*dx);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)+ dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)+ dQx(ii,jj)*d1Hq(ii,jj)*dz/(2*dx); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                

end 
end




%---------- (9) dQx d/dq ( H ( int ( dQx dV/dq ) ) --------------;

%---------- (9,a) dQx H dQx d/dq ( int ( dV/dq ) ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)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*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)-dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)-dQx(ii,jj)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+dQx(ii,jj)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (10) dQx d/dq ( H ( int ( dZx dV/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,Nz)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,Nz)/(2*dy);                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)-dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)-dQx(ii,jj)*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,Nz)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,Nz)/(2*dy);         
            
end 
end




%---------- (11) Kp1 dQy d/dq ( H ( int ( dQy dV/dq ) ) --------------;

%--------- (11,a) Kp1 dQy H dQy d/dq ( int ( dV/dq ) ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+Kp1*dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*dQy(ii)^2*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*Kp1*dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-Kp1*dQy(ii)^2*HIC(ii,jj)*dz/dy^2;                

            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+Kp1*dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+Kp1*dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp1*dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;         
            
end 
end




%---------- (11,b) Kp1 dQy dH/dq dQy int ( dV/dq ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)-Kp1*dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)-Kp1*dQy(ii)^2*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp1*dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+Kp1*dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+Kp1*dQy(ii)^2*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp1*dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (12) Kp1 dQy d/dq ( H ( int ( dZy dV/dz ) ) ----------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + Kp1*dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQy(ii)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp1*dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,Nz)/(2*dy) + Kp1*dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,Nz)/(2*dy);                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)-Kp1*dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - Kp1*dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)-Kp1*dQy(ii)*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp1*dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,Nz)/(2*dy) - Kp1*dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,Nz)/(2*dy);         

end 
end




%---------- (13) Kp2 dQy d/dq ( H ( int ( dU/dx ) ) ----------------;

%---------- (13,a) Kp2 dQy H d/dq ( int ( dU/dx ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp2*dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+1)- Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+p)- Kp2*dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-2)*Nz+Nz)-Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
                                                                           

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+1)- Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+p)- Kp2*dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+jj*Nz+Nz)-Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                

            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+1)+ Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+p)+ Kp2*dQy(ii)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+jj*Nz+Nz)+Kp2*dQy(ii)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
            
end 
end



%---------- (13,b) Kp2 dQy dH/dq int ( dU/dx ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)- Kp2*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                                                         
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+p)- Kp2*dQy(ii)*d1Hq(ii,jj)*dz/(2*dx);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-Kp2*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)+ Kp2*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                     
for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+p)+ Kp2*dQy(ii)*d1Hq(ii,jj)*dz/(2*dx); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)+Kp2*dQy(ii)*0.5*d1Hq(ii,jj)*dz/(2*dx);                

end 
end




%---------- (14) Kp2*dQy d/dq ( H ( int ( dQx dU/dq ) ) --------------;

%---------- (14,a) Kp2*dQy H dQx d/dq ( int ( dU/dq ) ) --------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp2*dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp2*dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+Kp2*dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp2*dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*Kp2*dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-Kp2*dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;                



MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+Kp2*dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+Kp2*dQy(ii)*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp2*dQy(ii)*0.5*HIC(ii,jj)*dQx(ii,jj)*dz/dy^2;         
            
end 
end




%---------- (14,b) Kp2*dQy d/dq ( H dQx ) int ( dU/dq ) ------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)-Kp2*dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+p)-Kp2*dQy(ii)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-Kp2*dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);                
                                                                           


MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)+Kp2*dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)=     MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+p)+Kp2*dQy(ii)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+Kp2*dQy(ii)*0.5*d2QxHq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (15) Kp2 dQy d/dq ( H ( int ( dZx dU/dz ) ) ----------------;

%---- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp2*dQy(ii)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + Kp2*dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny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z+jj*Nz+Nz)+Kp2*dQy(ii)*HIC(ii,jj+1)*dZz(ii,jj+1)/(2*dy);
          
end 
end



%------------------ - KpE dHb/dy P' -----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj) - KpE*dHby(ii,jj);                                                          
end 
end




%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ + KpE dens Freq^2 V +++++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

for ii=2:1:Nx-1 
for jj=2:1:Ny-1
  
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

for p=2:1:Nz-1                                                         
 MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p) + KpE*dens*Freq^2*dz*HIC(ii,jj);  
end

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)+ KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

end 
end



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++++ The third equation +++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) d/dx ( H ( int ( dZz dU/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+ HIC(ii-1,jj)*dZz(ii-1,jj)/(2*dx);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-HIC(ii-1,jj)*dZz(ii-1,jj)/(2*dx);



MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+1)- HIC(ii+1,jj)*dZz(ii+1,jj)/(2*dx);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,ii*Ny*Nz+(jj-1)*Nz+Nz)+HIC(ii+1,jj)*dZz(ii+1,jj)/(2*dx);

end 
end



%---------- (2) d/dx ( H ( int (dW/dx) ) ----------------;

%---------- (2,a) H d/dx ( int (dW/dx) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+0.5*HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii,jj)*dz/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)+0.5*HIC(ii,jj)*dz/dx^2;                

                                                                           

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-HIC(ii,jj)*dz/dx^2;

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*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jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+0.5*d1Hx(ii,jj)*dz/(2*dx);         
            
end 
end




%---------- (3) d/dx ( H ( int ( dQx dW/dq ) ) ----------------;

%---------- (3,a) H dQx d/dx ( int ( dW/dq ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                

                                                                           
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)-0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                


MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)-0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                

            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ 0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)+0.5*HIC(ii,jj)*dQx(ii,jj)*dz/(4*dx*dy);                
            
end 
end



%---------- (3,b) d/dx (H dQx) int ( dW/dq ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)- 0.5*d2QxHx(ii,jj)*dz/(2*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)- d2QxHx(ii,jj)*dz/(2*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-0.5*d2QxHx(ii,jj)*dz/(2*dy);                

                                                                           
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+ 0.5*d2QxHx(ii,jj)*dz/(2*dy);                                     
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+ d2QxHx(ii,jj)*dz/(2*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+0.5*d2QxHx(ii,jj)*dz/(2*dy);                
         
end 
end




%---------- (4) d/dx ( H ( int ( dZx dW/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+HIC(ii-1,jj)*dZx(ii-1,jj,1)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,1)/(2*dx);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,p)/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-HIC(ii-1,jj)*dZx(ii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nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+ dQx(ii,jj)*HIC(ii,jj-1)*dZz(ii,jj-1)/(2*dy);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*HIC(ii,jj-1)*dZz(ii,jj-1)/(2*dy);



MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+1)- dQx(ii,jj)*HIC(ii,jj+1)*dZz(ii,jj+1)/(2*dy);

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*HIC(ii,jj+1)*dZz(ii,jj+1)/(2*dy);
          
end 
end




%---------- (6) dQx d/dq ( H ( int ( dW/dx ) ) ----------------;

%---------- (6,a) dQx H d/dq ( int ( dW/dx ) ) ----------------;

%----- 1<j<Ny ----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+Nz)+dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                


MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
                                                                           

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                     
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+Nz)-dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                

            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ dQx(ii,jj)*HIC(ii,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*0.5*HIC(ii,jj)*dz/(4*dx*dy);                
            
end 
end




%---------- (6,b) dQx dH/dq int ( dW/dx ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)- dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                                                         
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)- dQx(ii,jj)*d1Hq(ii,jj)*dz/(2*dx);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+Nz)-dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                


MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)+ dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                                     
for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)+ dQx(ii,jj)*d1Hq(ii,jj)*dz/(2*dx); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+Nz)+dQx(ii,jj)*0.5*d1Hq(ii,jj)*dz/(2*dx);                

end 
end




%---------- (7) dQx d/dq ( H ( int ( dQx dW/dq ) ) --------------;

%--------- (7,a) dQx H dQx d/dq ( int ( dW/dq ) ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+dQx(ii,jj)^2*0.5*HIC(ii,jj)*dz/dy^2;                
                                                                           


MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*dQx(ii,jj)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*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B(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)-dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)-dQx(ii,jj)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);                
                                                                           


MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+dQx(ii,jj)*d2QxHq(ii,jj)*dz/(2*dy); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*0.5*d2QxHq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (8) dQx d/dq ( H ( int ( dZx dW/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,p)/(2*dy); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,Nz)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,Nz)/(2*dy);                



MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)-dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)-dQx(ii,jj)*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,p)/(2*dy); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,Nz)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,Nz)/(2*dy);         
            
end 
end




%---------- (9) dQy d/dq ( H ( int ( dZz dV/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB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(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;                
                                                                           


MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQy(ii)^2*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-2*dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)-dQy(ii)^2*HIC(ii,jj)*dz/dy^2;                

            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+dQy(ii)^2*HIC(ii,jj)*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQy(ii)^2*0.5*HIC(ii,jj)*dz/dy^2;         
            
end 
end



%---------- (10,b) dQy dH/dq dQy int ( dW/dq ) --------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)-dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)-dQy(ii)^2*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)-dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);                
                                                                           


MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)=     MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+dQy(ii)^2*d1Hq(ii,jj)*dz/(2*dy); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+Nz)+dQy(ii)^2*0.5*d1Hq(ii,jj)*dz/(2*dy);         
            
end 
end




%---------- (11) dQy d/dq ( H ( int ( dZy dW/dz ) ) ----------------;

%----- 1<j<Ny -----;

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                     
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:Nz-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+Nz)=MB(2*Nx*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MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj) + KpE;                                                          
end 
end




%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++ + KpE dens Freq^2 int ( W ) +++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


for ii=2:1:Nx-1 
for jj=2:1:Ny-1
    
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

for p=2:1:Nz-1                                                         
 MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p) + KpE*dens*Freq^2*dz*HIC(ii,jj);  
end

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)+ KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

end 
end






%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++ The momentum equations inside the ice shelf +++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++ 1<Ix<Nx; 1<Jy<Ny; 1<Kz<Nz +++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;



%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++++ The first equation +++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) Kp1 d/dx ( H ( int (dU/dx) ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp1*0.5*GpHInt1_ij(ii,jj)*dz/dx^2;                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-1)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-1)*Nz+2)+Kp1*0.5*GpHInt1_ij(ii,jj)*dz/dx^2;
 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+2)-Kp1*0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-1)*Nz+1)+Kp1*0.5*GpHInt1_ij(ii+1,jj)*dz/dx^2;            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-1)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-1)*Nz+2)+Kp1*0.5*GpHInt1_ij(ii+1,jj)*dz/dx^2;

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp1*0.5*GpHInt1_ij(ii,jj)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+p)+Kp1*GpHInt1_ij(ii,jj)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)+Kp1*0.5*GpHInt1_ij(ii,jj)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-Kp1*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-Kp1*0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;                

end
            

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+1)+Kp1*0.5*GpHInt1_ij(ii+1,jj)*dz/dx^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+p)+Kp1*GpHInt1_ij(ii+1,jj)*dz/dx^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+kk)+Kp1*0.5*GpHInt1_ij(ii+1,jj)*dz/dx^2;         
end
            
end 
end


%---------- (2) Kp1 d/dx ( H ( int ( dQx dU/dq ) ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+Kp1*0.5*HIC(ii-1,jj)*dQx(ii-1,jj)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+2)=        MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+2)+Kp1*0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ Kp1*0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp1*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+Kp1*0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)- Kp1*0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)- Kp1*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)-Kp1*0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)- Kp1*0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)- Kp1*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)-Kp1*0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)+ Kp1*0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+p)+ Kp1*HIC(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(ii+1,jj,2)/(2*dx) - Kp1*0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,2)/(2*dx);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp1*HIC(ii-1,jj)*dZx(ii-1,jj,1)/(2*dx) + Kp1*0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+p)+Kp1*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)-Kp1*HIC(ii-1,jj)*dZx(ii-1,jj,kk)/(2*dx) + Kp1*0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,kk)/(2*dx);                
end


for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+1)-Kp1*HIC(ii+1,jj)*dZx(ii+1,jj,1)/(2*dx) - Kp1*0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+p)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5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp2*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+Kp2*0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- Kp2*0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- Kp2*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)-Kp2*0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- Kp2*0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- Kp2*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)-Kp2*0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ Kp2*0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ Kp2*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny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ny*Nz+(jj-1)*Nz+2)+Kp2*HIC(ii+1,jj)*dZy(ii+1,jj,2)/(2*dx) - Kp2*0.5*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,2)/(2*dx);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp2*HIC(ii-1,jj)*dZy(ii-1,jj,1)/(2*dx) + Kp2*0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+Kp2*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)-Kp2*HIC(ii-1,jj)*dZy(ii-1,jj,kk)/(2*dx) + Kp2*0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,kk)/(2*dx);                
end


for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)-Kp2*HIC(ii+1,jj)*dZy(ii+1,jj,1)/(2*dx) - Kp2*0.5*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)-Kp2*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,p)/(2*dx); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+kk)+Kp2*HIC(ii+1,jj)*dZy(ii+1,jj,kk)/(2*dx) - Kp2*0.5*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,kk)/(2*dx);         
end
            
end 
end



%---------- (6) Kp2 d/dx ( H ( int ( dZz dW/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+Kp2*HIC(ii-1,jj)*dZz(ii-1,jj)/(2*dx);                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+2)-Kp2*HIC(ii-1,jj)*dZz(ii-1,jj)/(2*dx);

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)=    MB((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z+2,(ii-2)*Ny*Nz+jj*Nz+2)-Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);
 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+1)=        MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+1)+Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                        
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+2)=        MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+2)+Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)- Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)- Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)-Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)- Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)- Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)-Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)+ Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+p)+ Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+kk)+Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
end 
end


%---------- (8) Kp1 dQx d/dq ( H ( int ( dQx dU/dq ) ) --------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+2)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;
 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+2)-Kp1*dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQx(ii,jj)*GpHdQInt2_ij(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-Kp1*dQx(ii,jj)*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-Kp1*dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)+Kp1*dQx(ii,jj)*GpHdQInt2_ij(ii,jj+1)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)+Kp1*dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;         
end
            
end 
end



%---------- (9) Kp1 dQx d/dq ( H ( int ( dZx dU/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+2)-Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,2)/(2*dy) + Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,2)/(2*dy);

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)-Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)+Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,2)/(2*dy) - Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,2)/(2*dy);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)-Kp1*dQx(ii,jj)*HIC(ii,jj-1)*dZx(ii,jj-1,kk)/(2*dy) + Kp1*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,kk)/(2*dy);                
end


for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)-Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)-Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)+Kp1*dQx(ii,jj)*HIC(ii,jj+1)*dZx(ii,jj+1,kk)/(2*dy) - Kp1*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,kk)/(2*dy);         
end
            
end 
end



%---------- (10) Kp2 dQx d/dq ( H ( int ( dQy dV/dq ) ) --------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp2*dQx(ii,jj)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+2)+Kp2*dQx(ii,jj)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;
 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+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                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp2*dQx(ii,jj)*GpHdQInt3_ij(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+Kp2*dQx(ii,jj)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp2*dQx(ii,jj)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-Kp2*dQx(ii,jj)*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-Kp2*dQx(ii,jj)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+Kp2*dQx(ii,jj)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+Kp2*dQx(ii,jj)*GpHdQInt3_ij(ii,jj+1)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+kk)+Kp2*dQx(ii,jj)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;         
end
            
end 
end



%---------- (11) Kp2 dQx d/dq ( H ( int ( dZy dV/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp2*dQx(ii,jj)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + Kp2*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,N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for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp2*dQx(ii,jj)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)-Kp2*dQx(ii,jj)*HIC(ii,jj-1)*dZy(ii,jj-1,kk)/(2*dy) + Kp2*dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,kk)/(2*dy);                
end


for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)-Kp2*dQx(ii,jj)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - Kp2*dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)-Kp2*dQx(ii,jj)*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+j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1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*GpHdQInt3_ij(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQy(ii)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-dQy(ii)*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-dQy(ii)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)+dQy(ii)*GpHdQInt3_ij(ii,jj+1)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;         
end
            
end 
end



%---------- (14) dQy d/dq ( H ( int ( dZy dU/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+2)-dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,2)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,2)/(2*dy);

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)-dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)+dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,2)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,2)/(2*dy);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)-dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,kk)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,kk)/(2*dy);                
end


for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)-dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)-dQy(ii)*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)+dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,kk)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,kk)/(2*dy);         
end
            
end 
end


%---------- (15) dQy d/dq ( H ( int ( dV/dx ) ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+2)=MB((ii-1)*Ny*Nz+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ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+2)+dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ dQy(ii)*HIC(ii,jj-1)*dz/(4*dx*dy);  
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- dQy(ii)*HIC(ii,jj-1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)-dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- dQy(ii)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)-dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ dQy(ii)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)+dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
end 
end



%---------- (16) dQy d/dq ( H ( int ( dQx dV/dq ) ) --------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;                             
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+2)+dQy(ii)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;
 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQy(ii)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2)-dQy(ii)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+2)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+2)+dQy(ii)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*GpHdQInt2_ij(ii,jj)*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+dQy(ii)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQy(ii)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-dQy(ii)*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-dQy(ii)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB((ii-1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)*Ny*Nz+jj*Nz+1)-dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);            
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+2)=    MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+2)+dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,2)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,2)/(2*dy);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)-dQy(ii)*HIC(ii,jj-1)*dZx(ii,jj-1,kk)/(2*dy) + dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,kk)/(2*dy);                
end


for kk=3:1:Nz-1                 

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)-dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)-dQy(ii)*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,p)/(2*dy); 
end                                            

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+kk)+dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,kk)/(2*dy) - dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,kk)/(2*dy);         
end
            
end 
end



%--------------------- Kp1 H dZ/dx dU/dx  ---------------------;

for ii=2:1:Nx-1 
for jj=2:1:Ny-1
for kk=2:1:Nz-1 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)+Kp1*HIC(ii,jj)*dZx(ii,jj,kk)*(-1/(2*dx)); 
MB((ii-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nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk+1)-dZx(ii,jj,kk)*(1/(2*dz)); 
end 
end 
end


%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ + KpE dens Freq^2 U +++++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

for ii=2:1:Nx-1 
for jj=2:1:Ny-1
    
MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+1)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+1) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+2)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-1)*Nz+2) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

end 
end


for ii=2:1:Nx-1 
for jj=2:1:Ny-1
    
for kk=3:1:Nz-1 
MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

for p=2:1:kk-1                                                         
 MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p) + KpE*dens*Freq^2*dz*HIC(ii,jj);  
end

MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB((ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)+ KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);
end

end 
end





%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++++ The second equation +++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%------------- (1) d/dx ( H ( int ( dQy dU/dq ) ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-2)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                             
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-2)*Nz+2)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-2)*Nz+2)+0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+jj*Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+jj*Nz+1)-0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+jj*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+jj*Nz+2)-0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-2)*Nz+1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-2)*Nz+1)-0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-2)*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+(jj-2)*Nz+2)-0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+1)=        MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+1)+0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                        
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+2)=        MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,ii*Ny*Nz+jj*Nz+2)+0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ 0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)- 0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)- HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)-0.5*HIC(ii-1,jj)*dQy(ii-1)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)- 0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)- HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)-0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)+ 0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+p)+ HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+kk)+0.5*HIC(ii+1,jj)*dQy(ii+1)*dz/(4*dx*dy);                
end
            
end 
end



%---------- (2) d/dx ( H ( int ( dZ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+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+1)+HIC(ii-1,jj)*dZy(ii-1,jj,1)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-1)*Nz+kk)-HIC(ii-1,jj)*dZy(ii-1,jj,kk)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zyz(ii-1,jj,kk)/(2*dx);                
end


for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+1)-HIC(ii+1,jj)*dZy(ii+1,jj,1)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zyz(ii+1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-1)*Nz+p)-HIC(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)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)+0.5*GpHInt1_ij(ii,jj)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1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Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+2)=        MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+2)+0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ 0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- 0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)-0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- 0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)-0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ 0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)+0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                
end
            
end 
end



%---------- (5) d/dx ( H ( int ( dZx dV/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*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ny*Nz+(jj-1)*Nz+1)+HIC(ii-1,jj)*dZx(ii-1,jj,1)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,p)/(2*dx); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)-HIC(ii-1,jj)*dZx(ii-1,jj,kk)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,kk)/(2*dx);                
end


for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)-HIC(ii+1,jj)*dZx(ii+1,jj,1)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*N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2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+dQx(ii,jj)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQx(ii,jj)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-dQx(ii,jj)*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-dQx(ii,jj)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)+dQx(ii,jj)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                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Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)-dQx(ii,jj)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)+dQx(ii,jj)*HIC(ii,jj+1)*dZy(ii,jj+1,2)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,2)/(2*dy);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)-dQx(ii,jj)*HIC(ii,jj-1)*dZy(ii,jj-1,kk)/(2*dy) + dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,kk)/(2*dy);                
end


for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)-dQx(ii,jj)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)-dQx(ii,jj)*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)+dQx(ii,jj)*HIC(ii,jj+1)*dZy(ii,jj+1,kk)/(2*dy) - dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,kk)/(2*dy);         
end
            
end 
end



%---------- (8) dQx d/dq ( H ( int ( dV/dx ) ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)=MB(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(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+2)-dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);
 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)=        MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                        
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+2)=        MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+2)+dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ dQx(ii,jj)*HIC(ii,jj-1)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- dQx(ii,jj)*HIC(ii,jj-1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)-dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- dQx(ii,jj)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)-dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ dQx(ii,jj)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*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*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-dQx(ii,jj)*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-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ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQy(ii)*GpHdQInt3_ij(ii,jj)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+Kp1*dQy(ii)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp1*dQy(ii)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-Kp1*dQy(ii)*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-Kp1*dQy(ii)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+Kp1*dQy(ii)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)+Kp1*dQy(ii)*GpHdQInt3_ij(ii,jj+1)*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+kk)+Kp1*dQy(ii)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;         
end
            
end 
end



%---------- (12) Kp1 dQy d/dq ( H ( int ( dZy dV/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + Kp1*dQy(ii)*0.5*HIC(ii,jj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nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp1*dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,1)/(2*dy) + Kp1*dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp1*dQy(ii)*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)-Kp1*dQy(ii)*HIC(ii,jj-1)*dZy(ii,jj-1,kk)/(2*dy) + Kp1*dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zyz(ii,jj-1,kk)/(2*dy);                
end


for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)-Kp1*dQy(ii)*HIC(ii,jj+1)*dZy(ii,jj+1,1)/(2*dy) - Kp1*dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zyz(ii,jj+1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*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ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ Kp2*dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ Kp2*dQy(ii)*HIC(ii,jj-1)*dz/(4*dx*dy);  
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+Kp2*dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+1)- Kp2*dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+p)- Kp2*dQy(ii)*HIC(ii,jj-1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+(jj-2)*Nz+kk)-Kp2*dQy(ii)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+1)- Kp2*dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+p)- Kp2*dQy(ii)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-2)*Ny*Nz+jj*Nz+kk)-Kp2*dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+1)+ Kp2*dQy(ii)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,ii*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1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B(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+Kp2*dQy(ii)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+1)-Kp2*dQy(ii)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+p)-Kp2*dQy(ii)*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-Kp2*dQy(ii)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)+Kp2*dQy(ii)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
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1)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+1)-Kp2*dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - Kp2*dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);            
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)=    MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+jj*Nz+2)+Kp2*dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,2)/(2*dy) - Kp2*dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,2)/(2*dy);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+Kp2*dQy(ii)*HIC(ii,jj-1)*dZx(ii,jj-1,1)/(2*dy) + Kp2*dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+p)+Kp2*dQy(ii)*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+(jj-2)*Nz+kk)-Kp2*dQy(ii)*HIC(ii,jj-1)*dZx(ii,jj-1,kk)/(2*dy) + Kp2*dQy(ii)*0.5*HIC(ii,jj-1)*dz*d2Zxz(ii,jj-1,kk)/(2*dy);                
end


for kk=3:1:Nz-1                 

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+1)-Kp2*dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,1)/(2*dy) - Kp2*dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,1)/(2*dy);

for p=2:1:kk-1                                                         
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+p)-Kp2*dQy(ii)*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,p)/(2*dy); 
end                                            

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,(ii-1)*Ny*Nz+jj*Nz+kk)+Kp2*dQy(ii)*HIC(ii,jj+1)*dZx(ii,jj+1,kk)/(2*dy) - Kp2*dQy(ii)*0.5*HIC(ii,jj+1)*dz*d2Zxz(ii,jj+1,kk)/(2*dy);         
end
            
end 
end


%---------- (16) Kp2 dQy d/dq ( H ( int ( dZz dW/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*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jj-1)*Nz+2) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

end 
end


for ii=2:1:Nx-1 
for jj=2:1:Ny-1
    
for kk=3:1:Nz-1 
MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

for p=2:1:kk-1                                                         
 MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p) + KpE*dens*Freq^2*dz*HIC(ii,jj);  
end

MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)+ KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);
end

end 
end





%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++++++ The third equation ++++++++++++++++++++++;
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%---------- (1) d/dx ( H ( int ( dZz dU/dz ) ) ----------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+(jj-1)*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-2)*Ny*Nz+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)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+GpHInt1_ij(ii,jj)*dz/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)+0.5*GpHInt1_ij(ii,jj)*dz/dx^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-0.5*(GpHInt1_ij(ii,jj)+GpHInt1_ij(ii+1,jj))*dz/dx^2;                

end
            

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)+0.5*GpHInt1_ij(ii+1,jj)*dz/dx^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)+GpHInt1_ij(ii+1,jj)*dz/dx^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+kk)+0.5*GpHInt1_ij(ii+1,jj)*dz/dx^2;         
end
            
end 
end


%----------- (3) d/dx ( H ( int ( dQx dW/dq ) ) ----------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                             
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+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dy);
 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)=        MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                        
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+2)=        MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+2)+0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ 0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- 0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)-0.5*HIC(ii-1,jj)*dQx(ii-1,jj)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- 0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)-0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ 0.5*HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ HIC(ii+1,jj)*dQx(ii+1,jj)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)=MB(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ii*Ny*Nz+(jj-1)*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+2)+HIC(ii+1,jj)*dZx(ii+1,jj,2)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,2)/(2*dx);

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+1)+HIC(ii-1,jj)*dZx(ii-1,jj,1)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+p)+HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,p)/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-1)*Nz+kk)-HIC(ii-1,jj)*dZx(ii-1,jj,kk)/(2*dx) + 0.5*HIC(ii-1,jj)*dz*d2Zxz(ii-1,jj,kk)/(2*dx);                
end


for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+1)-HIC(ii+1,jj)*dZx(ii+1,jj,1)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,1)/(2*dx);

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+p)-HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,p)/(2*dx); 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-1)*Nz+kk)+HIC(ii+1,jj)*dZx(ii+1,jj,kk)/(2*dx) - 0.5*HIC(ii+1,jj)*dz*d2Zxz(ii+1,jj,kk)/(2*dx);         
end
            
end 
end


%----------- (5) dQx d/dq ( H ( int ( dZz dU/dz ) ) --------------;


for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)*HIC(ii,jj-1)*dZz(ii,jj-1)/(2*dy);                             
MB(2*Nx*Ny*N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*Ny*Nz+ii*Ny*Nz+jj*Nz+2)+dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);
 
end
end

for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                                                         
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+p)+ dQx(ii,jj)*HIC(ii,jj-1)*dz/(4*dx*dy);  
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+(jj-2)*Nz+kk)+dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end

for kk=3:1:Nz-1                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+p)- dQx(ii,jj)*HIC(ii,jj-1)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+(jj-2)*Nz+kk)-dQx(ii,jj)*0.5*HIC(ii,jj-1)*dz/(4*dx*dy);                
end
                                                                           
for kk=3:1:Nz-1                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+1)- dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                     
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+p)- dQx(ii,jj)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-2)*Ny*Nz+jj*Nz+kk)-dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
for kk=3:1:Nz-1                 
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+1)+ dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                                                                             
for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+p)+ dQx(ii,jj)*HIC(ii,jj+1)*dz/(4*dx*dy); 
end                                            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+ii*Ny*Nz+jj*Nz+kk)+dQx(ii,jj)*0.5*HIC(ii,jj+1)*dz/(4*dx*dy);                
end
            
end 
end


%---------- (7) dQx d/dq ( H ( int ( dQx dW/dq ) ) --------------;

for ii=2:1:Nx-1
for jj=2:1:Ny-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1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+(ii-1)*Ny*Nz+jj*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+2)+dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQx(ii,jj)*GpHdQInt2_ij(ii,jj)*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-dQx(ii,jj)*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-dQx(ii,jj)*0.5*(GpHdQInt2_ij(ii,jj)+GpHdQInt2_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQx(ii,jj)*0.5*GpHdQInt2_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2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jj*Nz+1)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;            
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+2)=    MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+2,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+2)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;

end
end


for ii=2:1:Nx-1
for jj=2:1:Ny-1
                                                      
for kk=3:1:Nz-1

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+1)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+p)+dQy(ii)*GpHdQInt3_ij(ii,jj)*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-2)*Nz+kk)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj)*dz/dy^2;                
end
                                                                           

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)-dQy(ii)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)-dQy(ii)*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2; 
end                                            

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)-dQy(ii)*0.5*(GpHdQInt3_ij(ii,jj)+GpHdQInt3_ij(ii,jj+1))*dz/dy^2;                

end
            

for kk=3:1:Nz-1                 

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+jj*Nz+1)+dQy(ii)*0.5*GpHdQInt3_ij(ii,jj+1)*dz/dy^2;

for p=2:1:kk-1                                                         
MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk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2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1)= MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+1) + KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);

for p=2:1:kk-1                                                         
 MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+p) + KpE*dens*Freq^2*dz*HIC(ii,jj);  
end

MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)=MB(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk)+ KpE*0.5*dens*Freq^2*dz*HIC(ii,jj);
end

end 
end




%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++ Sea Water under the Ice Shelf ++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
    
    
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%++++++++++++++++++++++++++++ W=W' +++++++++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
    
for ii=1:1:Nx
for jj=1:1:Ny
MB(3*Nx*Ny*Nz+(ii-1)*Ny+jj,2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+Nz)=-1;
MB(3*Nx*Ny*Nz+(ii-1)*Ny+jj,3*Nx*Ny*Nz+(ii-1)*Ny+jj)=1;
end
end
    

%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++ Wave equation & Boundary conditions +++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%--------------- X=0 (Ix=1): dP'/dx=0 ---------------;


for jj=1:1:Ny
    MB(3*Nx*Ny*Nz+Nx*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+jj)=     -3/(2*dx);
    MB(3*Nx*Ny*Nz+Nx*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+Ny+jj)=   4/(2*dx);
    MB(3*Nx*Ny*Nz+Nx*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+2*Ny+jj)=-1/(2*dx);
end




%---------- X=L (Ix=Nx): P'= p g dz sin(wt) ----------;

for jj=1:1:Ny

    MB(3*Nx*Ny*Nz+Nx*Ny+(Nx-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+(Nx-1)*Ny+jj)=1;
        
    
    VB(3*Nx*Ny*Nz+Nx*Ny+(Nx-1)*Ny+jj)=dens_w*g*AmSLC;
      
end




%------------- Y=Y1 (J=1): dP'/dy=0 ---------------;

for ii=2:1:Nx-1

    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+1,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+1)=-3/(2*dy);     
    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+1,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+2)= 4/(2*dy);
    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+1,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+3)=-1/(2*dy);
    
end



%------------- Y=Y1 (J=1): dP'/dn = dP'/dx dY1/dx + dQx dP'/dq dY1/dx - dQy dP'/dq = 0 ---------------;

% for ii=2:1:Nx-1
%     
%     MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+1,3*Nx*Ny*Nz+Nx*Ny+(ii-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3*Nx*Ny*Nz+Nx*Ny+(ii-2)*Ny+jj+1)+(1/dens_w)*(-WDQxy_ij(ii,jj+1)/(4*dy*dx)); 
    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+ii*Ny+jj+1)=    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+ii*Ny+jj+1)     +(1/dens_w)*(WDQxy_ij(ii,jj+1)/(4*dy*dx));
    
    
    %------ (5) dQx d/dq ( D dQx dP'/dq ) --------;
    
    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj-1)=MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj-1)+(1/dens_w)*(WDQx2y_ij(ii,jj)/dy^2);     
    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj)=  MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj)  +(1/dens_w)*(-(WDQx2y_ij(ii,jj)+WDQx2y_ij(ii,jj+1))/dy^2);
    MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj+1)=MB(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj,3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj+1)+(1/dens_w)*(WDQx2y_ij(ii,jj+1)/dy^2);
            
        
end
end

     

%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;

        
    SolveUVW=linsolve(MB,VB);
    
        
%-----------------------------------------------------------------;

for ii=1:1:Nx
for jj=1:1:Ny
for kk=1:1:Nz 
    masU(ii,jj,kk)=SolveUVW((ii-1)*Ny*Nz+(jj-1)*Nz+kk); 
end 
end
end
                                                                           
for ii=1:1:Nx 
for jj=1:1:Ny
for kk=1:1:Nz 
    masV(ii,jj,kk)=SolveUVW(Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk); 
end 
end
end

for ii=1:1:Nx
for jj=1:1:Ny
for kk=1:1:Nz 
    masW(ii,jj,kk)=SolveUVW(2*Nx*Ny*Nz+(ii-1)*Ny*Nz+(jj-1)*Nz+kk); 
end 
end
end


for ii=1:1:Nx
for jj=1:1:Ny 
    Delta_H(ii,jj,JFreq)=SolveUVW(3*Nx*Ny*Nz+(ii-1)*Ny+jj); 
end
end


for ii=1:1:Nx
for jj=1:1:Ny 
    Delta_P(ii,jj,JFreq)=SolveUVW(3*Nx*Ny*Nz+Nx*Ny+(ii-1)*Ny+jj); 
end
end
    

for ii=1:1:Nx
for jj=1:1:Ny 
    Delta_Ws(ii,jj,JFreq)=masW(ii,jj,1); 
end
end


%---------------------------------------------------------------------;
%--------------------- Wavelength, Wavenumber ------------------------;
%---------------------------------------------------------------------;

Jy=round(Ny/2);
    
for ii=1:1:Nx, Delta_HX(ii)=masW(ii,Jy,1); end


WX_interp=interp1(L_X,Delta_HX,L_X_interp,'spline');


L_X_node_max=zeros(Nx_interp,1);

L_X_node_min=zeros(Nx_interp,1);

N_max=0; N_min=0;


%---------------------;


for ii=3:1:Nx_interp-2
    
            
    if (WX_interp(ii-2)<WX_interp(ii-1)) && (WX_interp(ii-1)<WX_interp(ii)) && (WX_interp(ii+1)<WX_interp(ii)) && (WX_interp(ii+2)<WX_interp(ii+1))
        
        N_max=N_max+1;
        
        L_X_node_max(N_max)=L_X_interp(ii);
                
    end
    
            
    if (WX_interp(ii-2)>WX_interp(ii-1)) && (WX_interp(ii-1)>WX_interp(ii)) && (WX_interp(ii+1)>WX_interp(ii)) && (WX_interp(ii+2)>WX_interp(ii+1))    
                
        N_min=N_min+1;
        
        L_X_node_min(N_min)=L_X_interp(ii);
                
    end
            
end


%----------------------;


L_Wave_max=0;

if N_max>1
    
    for ii=1:1:N_max-1
        
        L_Wave_max=L_Wave_max+(L_X_node_max(ii+1)-L_X_node_max(ii));
              
    end
    
    L_Wave_max=L_Wave_max/(N_max-1);
    
end


%--------------------;


L_Wave_min=0;

if N_min>1
    
    for ii=1:1:N_min-1
        
        L_Wave_min=L_Wave_min+(L_X_node_min(ii+1)-L_X_node_min(ii));
              
    end
    
    L_Wave_min=L_Wave_min/(N_min-1);
    
end


if (L_Wave_max>0) && (L_Wave_min>0), L_Wave=(L_Wave_max+L_Wave_min)/2; end

if (L_Wave_max>0) && (L_Wave_min==0), L_Wave=L_Wave_max; end

if (L_Wave_max==0) && (L_Wave_min>0), L_Wave=L_Wave_min; end

if (L_Wave_max==0) && (L_Wave_min==0), L_Wave=0; end


%---------------------------------------;

Length_Wave(JFreq)=L_Wave;

Wavenumber(JFreq)=(2*pi)/L_Wave;


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++;

max_Delta_H(JFreq)=0;

for ii=1:1:Nx 
    for jj=1:1:Ny
        if max_Delta_H(JFreq)<abs(Delta_H(ii,jj,JFreq)), max_Delta_H(JFreq)=abs(Delta_H(ii,jj,JFreq)); end 
    end
end



%+++++++++++++++++++++++++++++++++++++++++++++++++++++++;

    disp(JFreq);
    
    datestr(clock)


end


%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;
%+++++++++++++++++++++++ THE MAIN CYCLE END ++++++++++++++++++++++++++++;
%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++;


%-----------------------------------------------------------------------;
%------------------ Results: the dispersion spectra --------------------;
%------------ ( the wavenumder vs periodicity/frequency )---------------;
%-----------------------------------------------------------------------;


L_Freq1=zeros(NFreq,1); L_Freq2=zeros(NFreq,1); L_PT=zeros(NFreq,1);


for JFreq=1:1:NFreq, L_Freq1(JFreq)=2*pi/(PT0+JFreq*D_PT); end

for JFreq=1:1:NFreq, L_Freq2(JFreq)=1/(PT0+JFreq*D_PT); end

for JFreq=1:1:NFreq, L_PT(JFreq)=PT0+JFreq*D_PT; end



figure(6);

plot(L_Freq1,Wavenumber,'-r.'), title('Dispersion Spectrum'), xlabel('Freq (Hz)'), ylabel('Wavenumber (m^-1)'), grid;


figure(7);

plot(L_PT,Wavenumber,'-r.'), title('Dispersion Spectrum'), xlabel('Periodicity (s)'), ylabel('Wavenumber (m^-1)'), grid;


save D:\Results\Freq1.txt -ascii L_Freq1

save D:\Results\Freq2.txt -ascii L_Freq2

save D:\Results\Periodicity.txt -ascii L_PT


save D:\Results\Wavenumber.txt -ascii Wavenumber

%------------------------------------------------------------------;


