User:Eml4500.f08.team.foskey.ckf/hw5a

MATLAB Assignment  Debugging the Two Bar Truss problem 

Two Bar Truss Code
The original two bar truss code was a modification of an earlier code that evaluated a truss composed of bars with eqaul material and physical properties. However, the two bar truss problem was composed of bars with unequal properties. This new, "debugged" code corrects that issue. The debugged code is a s follows:

Additional Functions
The following functions are used in the main code of TwoBarTrussDebugged.m, and are needed for the main code to run.

What The Function PlaneTrussElement Does
The function PlaneTrussElement reads in the Young's Modulus, the cross sectional area of a bar, and the coordinates of the endpoints of a two dimensional bar. The function then uses the coordinates to calculate the length of the bar. Next, the function calculates the director cosines. Finally, the function calculates the elemental stiffness matrix of the bar. This elemental stiffness matrix is returned to the original call function.

What NodalSoln Does
The function NodalSoln reads in the global stiffness matrix, the applied loads, a matrix ,debc, containing the degrees of freedom with specified values (in this case the constrained degrees of freedom), and a matrix, ebcVals ,with the values of the nodes (in this case zeros). The function first calculates the number of global degrees of freedom. Through several steps, the function ultimately calculates the global displacements, and the reactions (in a global coordinate system) of the bars. The displacement matrix, and reaction matrix is returned to the original call function.

What PlaneTrussResults Does
The function PlaneTrussResults reads in the Young's Modulus, the cross sectional area, the coordinates of the endpoints of a bar, and the displacements of a two dimensional (plane) bar. The function first calculates the length of the bar, and then calculates the director cosines. Next, the function creates a transform matrix T that transforms the global displacements into axial displacements. From there, the function calculates the strain, stress, and axial forces acting on the bar. These values are then returned to the calling function.

Comments on the changes to the code
As stated above, the original two bar truss code was based on a problem for which the bars making up the truss all had the same Young's Modulus and cross sectional area values. In that first problem these values were constants and were coded as such. In the two bar truss problem, each truss has a different value for its Young's Modulus (e) and cross sectional area (A). In the two bar truss problem, those values are coded as 2x1 matrices. However, when the PlaneTrussResults function is called, the original call is made, in which the values for "e" and "A" were constants. Since in the two bar truss problem these values are matrices, the entire matrix is passes, instead of just the values for one of the bars.

To correct the "bug" in the code, the values in the function call were changed to reflect that they needed to be elements of a matrix.

As a result, the last nine lines of code goes from the incorrect

to the corrected

with the only true change being the addition of "(i)" after the variables "e" and "A" in the function call of PlaneTrussResults.

To see the complete Incorrect code for the two bar truss, click here

Results
Running the above TwoBarTrussDebugged.m file generates the following results output:

k_local = 0.75       -0.75        -0.75         0.75  k = 0.5625     0.32476      -0.5625     -0.32476      0.32476       0.1875     -0.32476      -0.1875      -0.5625     -0.32476       0.5625      0.32476     -0.32476      -0.1875      0.32476       0.1875  k_local = 5   -5    -5     5  k = 2.5        -2.5         -2.5          2.5         -2.5          2.5          2.5         -2.5         -2.5          2.5          2.5         -2.5          2.5         -2.5         -2.5          2.5  K = 0.5625     0.32476      -0.5625     -0.32476            0            0      0.32476       0.1875     -0.32476      -0.1875            0            0      -0.5625     -0.32476       3.0625      -2.1752         -2.5          2.5     -0.32476      -0.1875      -2.1752       2.6875          2.5         -2.5            0            0         -2.5          2.5          2.5         -2.5            0            0          2.5         -2.5         -2.5          2.5  R = 0    0     0     7     0     0  d = 0           0        4.352       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

Comments on results
Running the TwoBarTrussDebugged.m file provided the above results. The results show the local stiffness matrix, and elemental stiffness matrix (in the global coordinate system) for element one, and two. The results next show the global stiffness matrix, K, the applied loads R, and global displacements d. The reactions matrix gives the reaction forces acting at each node. The results matrix gives the strain (in column 1), stress (column 2), and axial forces (column 3) acting in element 1 ( in row 1), and element 2 ( in row 2).

By debugging the code, the results output is corrected, specifically the actual results matrix. The original results matrix is a 2x4 matrix of essentially garbage values generated by a function call that passes an entire matrix, as opposed to a single value from that matrix.

The original, incorrect results output can be seen at HW2 MATLAB portion