function [A,b,nDir,nodesDir1,nodesDir0] = BoundaryConditions(X,velo, nx, ny)

x1 = min(X(:,1)); x2 = max(X(:,1)); xM = (x1+x2)/2;
y1 = min(X(:,2)); y2 = max(X(:,2)); yM = (y1+y2)/2; 

if velo == 1
     nodes_x1 = find( (abs(X(:,1) - x1)<1e-6)); 
     nodes_x2 = find( (abs(X(:,1) - x2)<1e-6)); 
     nodes_y1 = find( (abs(X(:,2) - y1)<1e-6)); 
     nodes_y2 = find( (abs(X(:,2) - y2)<1e-6));    
    
    % nodes on which solution is u=0
    nodesDir1 = nodes_x1( X(nodes_x1,2) > 1.5 );
    % nodes on which solution is u=1
    nodesDir0 = [nodes_x2];
    % Boundary condition matrix
    C = [nodesDir1, zeros(length(nodesDir1),1); 
         nodesDir0, zeros(length(nodesDir0),1)];
     
elseif velo == 2
    nodesDir = find( (abs(X(:,1) - x2)<1e-6)); 
    C = [nodesDir, zeros(size(nodesDir))]; 
elseif velo == 3
    nodes_x2 = find( (abs(X(:,1) - x2)<1e-6)); 
    nodes_y2 = find( (abs(X(:,2) - y2)<1e-6)); 
    nodesDir = unique([nodes_x2;nodes_y2]);
    C = [nodesDir, zeros(size(nodesDir))]; 
end

nDir = size(C,1); 
nPt = size(X,1); 
A = zeros(nDir,nPt);
A(:,C(:,1)) = eye(nDir); 
b = C(:,2); 
