User:Eml4500.f08.bottle.ranto/HW5

Debugging of Two Bar Truss Code
The code given in conjunction with the second homework report contained an error which was to be corrected. The previous code returned an error when attempting to generate a results matrix. This error was caused by the lines:

for i=1:elems results = [results; PlaneTrussResults(e, A, ...           nodes(conn(i,:),:), d(lmm(i,:)))]; end

This section of code attempted to pass two arrays as scalar values.

To fix this problem, the code was modified to read:

for i=1:elems results = [results; PlaneTrussResults(e(i), A(i), ...   nodes(conn(i,:),:), d(lmm(i,:)))]; end

The code in its entirety is as follows:

% Debugged Two-Bar Truss System Code clear all; e = [3 5]; A = [1 2]; P = 7; L=[4 2]; alpha = pi/3; beta = pi/4; nodes = [ 0, 0; % x,y position of node 1 L(1)*cos(pi/2-alpha), L(1)*sin(pi/2-alpha); % x,y position of node 2 L(1)*cos(pi/2-alpha)+L(2)*sin(beta),L(1)*sin(pi/2-alpha)-L(2)*cos(beta) % x,y position of node 3 ]; dof=2*length(nodes); conn=[1,2; 2,3]; lmm = [1, 2, 3, 4; 3, 4, 5, 6]; elems=size(lmm,1); K=zeros(dof); R = zeros(dof,1); debc = [1, 2, 5, 6]; ebcVals = zeros(length(debc),1); %load vector R = zeros(dof,1); R(4) = P; % Assemble global stiffness matrix K=zeros(dof); for i=1:elems lm=lmm(i,:); con=conn(i,:); k_local=e(i)*A(i)/L(i)*[1 -1; -1 1] k=PlaneTrussElement(e(i), A(i), nodes(con,:)) K(lm, lm) = K(lm, lm) + k; end K R % Nodal solution and reactions [d, reactions] = NodalSoln(K, R, debc, ebcVals) results=[]; for i=1:elems results = [results; PlaneTrussResults(e(i), A(i), ...   nodes(conn(i,:),:), d(lmm(i,:)))]; end format short g results

This correction yields the following results:

k_local = 0.750  -0.750   -0.750    0.750 k = 0.5625   0.3248   -0.5625   -0.3248    0.3248    0.1875   -0.3248   -0.1875   -0.5625   -0.3248    0.5625    0.3248   -0.3248   -0.1875    0.3248    0.1875 k_local = 5   -5    -5     5 k = 2.5000  -2.5000   -2.5000    2.5000   -2.5000    2.5000    2.5000   -2.5000   -2.5000    2.5000    2.5000   -2.5000    2.5000   -2.5000   -2.5000    2.5000 K = 0.5625   0.3248   -0.5625   -0.3248         0         0    0.3248    0.1875   -0.3248   -0.1875         0         0   -0.5625   -0.3248    3.0625   -2.1752   -2.5000    2.5000   -0.3248   -0.1875   -2.1752    2.6875    2.5000   -2.5000         0         0   -2.5000    2.5000    2.5000   -2.5000         0         0    2.5000   -2.5000   -2.5000    2.5000 R = 0    0     0     7     0     0 d = 0        0    4.3520    6.1271         0         0 reactions = -4.4378  -2.5622    4.4378   -4.4378 results = 1.7081      5.1244       5.1244       0.6276        3.138        6.276