%
%   rectangular_plate_nodes_elements.m  ver 1.1  February 26, 2013
%
function[fig_num,number_nodes,node_matrix,element_matrix,nelem,...
                nodex,nodey,nx,ny,node1,node2,node3,node4,dof,L,W]=...
                        rectangular_plate_nodes_elements(fig_num)
%
disp(' ');
L=input(' Enter the length (inch) along the x-axis ');
disp(' ');
W=input(' Enter the width (inch)  along the y-axis ');
disp(' ');
disp(' ');
nx=input(' Enter the number of nodes along the x-axis ');
disp(' ');
ny=input(' Enter the number of nodes along the y-axis ');
disp(' ');
%
number_nodes=nx*ny;
%
dx=L/(nx-1);
dy=W/(ny-1);
%
ijk=1;
%
for j=1:ny
%    
    for i=1:nx
        node_matrix(ijk,1)=(i-1)*dx;
        node_matrix(ijk,2)=(j-1)*dy;        
        ijk=ijk+1;  
    end
%    
end
%
ne=(nx-1)*(ny-1);
nelem=ne;
%
j=1;
k=1;
for i=1:ne
%
    element_matrix(i,1)=j; 
    element_matrix(i,2)=j+1; 
    element_matrix(i,3)=element_matrix(i,2)+nx;
    element_matrix(i,4)=element_matrix(i,1)+nx;
%
    j=j+1;
    k=k+1;
    
    if(k==nx)
        j=j+1;
        k=1;
    end
%    
end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
figure(fig_num);
fig_num=fig_num+1;
plot(node_matrix(:,1),node_matrix(:,2),'.');
%
clear nodex;
clear nodey;
nodex=node_matrix(:,1);
nodey=node_matrix(:,2);
%
for i=1:number_nodes
   string=num2str(i,'%d\n');
   text(nodex(i),nodey(i),string);
end
xlabel('X');
ylabel('Y');
grid on;
%
xmax=max(nodex)+dx/2;
ymax=max(nodey)+dy/2;
%
xmin=min(nodex)-dx/2;
ymin=min(nodey)-dy/2;
%
axis([xmin,xmax,ymin,ymax]);
%
node1=element_matrix(:,1);
node2=element_matrix(:,2);
node3=element_matrix(:,3);
node4=element_matrix(:,4);
%
hold on;
%
for i=1:ne
    x=[ nodex(node1(i)) nodex(node2(i)) nodex(node3(i)) nodex(node4(i)) nodex(node1(i))];
    y=[ nodey(node1(i)) nodey(node2(i)) nodey(node3(i)) nodey(node4(i)) nodey(node1(i))];
    plot(x,y);
end
hold off;
%
%
dof=number_nodes*3;
%
disp(' Unconstrained model statistics ');
out1=sprintf('\n  nodes=%d  elements=%d   degrees-of-freedom=%d  \n',number_nodes,nelem,dof);
disp(out1);