function [ area, indx, nel, node, nunk, xc ] = geometry ( nnodes, nx ) % % [ area, indx, nel, node, nunk, xc ] = geometry ( nnodes, nx ) % % GEOMETRY sets up the geometric quantities for the finite element problem. % % NNODES is the number of nodes per element; % NX is the number of nodes total. % % AREA(NEL) is the "area" (length, really) of each element. % INDX(NX) is the index of the finite element coefficient associated with each node. % NEL is the number of elements. % NODE(NEL,NNODES) contains a list of the nodes that belong to each element. % NUNK is the number of finite element coefficients. % XC(NX) is the coordinates of the nodes. % xc = zeros(nx,1); % % The following code produces NX equally spaced nodes from XL to XR. % xl = 0.0; xr = 1.0; for i = 1 : nx xc(i) = ( ( nx - i ) * xl + ( i - 1 ) * xr ) / ( nx - 1 ); end % % Set the values of NODE, which indicate which nodes belong to each element. % nel = nx - 1; node = zeros(nel,nnodes); for i = 1 : nel node(i,1) = i; node(i,2) = i+1; end % % Set INDX, which links a node index to a coefficient index. % % In this case, INDX has a very simple form. In other cases, % some values of INDX might be zero. % indx = zeros(nx,1); nunk = 0; for i = 1 : nx nunk = nunk + 1; indx(i) = nunk; end % % Set AREA, the area of each element. % area = zeros(nel,1); for it = 1 : nel ip1 = node(it,1); ip2 = node(it,2); x1 = xc(ip1); x2 = xc(ip2); area(it) = abs ( x2 - x1 ); end