function [A,b,nDir,gamma2] = BoundaryConditions(X,nx,ny,p)

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

nodes_y0 = [2:p*nx]';                           % Nodes on the boundary y=0
nodes_x1 = [p*nx+1:p*nx+1:(p*ny+1)*(p*nx+1)]' ;     % Nodes on the boundary x=1
nodes_y1 = [p*ny*(p*nx+1)+p*nx:-1:ny*(p*nx+1)+2]' ;     % Nodes on the boundary y=1
nodes_x0 = [p*ny*(p*nx+1)+1:-(p*nx+1):1]';     % Nodes on the boundary x=0


gamma1=nodes_x0( X(nodes_x0,2) < 1.5);
gamma2=nodes_x0( X(nodes_x0,2) >= 1.5);
gamma=nodes_x0;
gamma3=nodes_y1;
gamma4=nodes_x1;
gamma5=nodes_y0;

% nodes on which solution is u=1
nodesDir1 = gamma;
% nodes on which solution is u=0
nodesDir0 = gamma4;
% Boundary condition matrix
C = [nodesDir1, zeros(length(nodesDir1),1);
     nodesDir0, zeros(length(nodesDir0),1)];

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