You are on page 1of 8

Carlos Joaquin C.

Santos 1st Trimester SY 2021-2022

MECp 1- Computer Application for ME Due Date: October 18, 2021

Assignment 2

Problem Title

Displacement of the Each Members of the Given Truss Solver by Gaussian Elimination

1. Problem Statement

A program that uses the Gaussian Elimination Method to solve the displacement or deformation of each
member of a given truss. Two different areas, two forces are given by the problem, modulus of elasticity and
the original length of each member are given the problem.

2. Results and Discussion

The first step is to analyze the given truss, as shown in image 2.1, one of the force is -1000 lb. It means
that there will be one(1) or more compression in the members of the given truss. After analyzing substitute all
the values to the given matrix.

Image 2.1
Given Matrix and Values:

[ ][ ]
By substituting all the values, the result is shown in the matrix below:

8 0 −4 0 0 0 −2 2 √3 0 0 0
0 12 0 0 0 0 2 √3 −6 0 0 −4 x 10
−3

−4 0 12 0 −4 0 −2 −2 √3 −2 2 √3 0
0 0 0 12 0 0 −2 √3 −6 2 √3 −6 −4 x 10−3
0 0 −4 0 8 0 0 0 −2 −2 √ 3 0
−2 √ 3 −6
−3
0 0 0 0 0 12 0 0 −4 x 10
−2 2 √ 3 −2 −2 √3 0 0 12 0 −4 0 0
−3
2 √ 3 −6 −2 √3 −6 0 0 0 12 0 0 −4 x 10
0 0 −2 2 √3 −2 −2 √ 3 −4 0 12 0 0
0 0 2 √ 3 −2 √3 −2 √ 3 −6 0 0 0 12 −4 x 10−3
As shown in the given matrix, all the values below the diagonal line must be equal to zero. To do that,
just like solving a linear system of equation, eliminate variables is done. In gauss elimination, all variable below
the diagonal will be eliminated to easily solve the value of X10 , since the given has 10 unknowns. The first step
is to set a formula to eliminate some value. In this case, I multiplied row 7 to √ 3 and the add it to row 8. Note
all values that are red, are the transformed row after following the formula.

√ 3 ( row 7 )+(row 8)

[ ][ ]
8 0 −4 0 0 0 −2 2√ 3 0 0 0
0 12 0 0 0 0 2√ 3 −6 0 0 −4 x 10
−3

−4 0 12 0 −4 0 −2 −2 √ 3 −2 2 √3 0
0 0 0 12 0 0 −2 √ 3 −6 2√3 −6 −4 x 10
−3

0 0 −4 0 8 0 0 0 −2 −2 √3 0
0 0 0 0 0 12 0 0 −2 √ 3 −6 −4 x 10−3
−2 2 √ 3 −2 −2 √ 3 0 0 12 0 −4 0 0
−3
0 0 −4 √ 3 −12 0 0 12 √ 3 12 −4 √3 0 −4 x 10
0 0 −2 2 √3 −2 −2 √ 3 −4 0 12 0 0
0 0 2 √3 −2 √ 3 −2 √ 3 −6 0 0 0 12 −4 x 10−3

As shown in the matrix above, row 8 column 1 is eliminated. Also, the entire row 8 values will change.
After that, repeat the process, until row 10 column 9 will be equal to zero.

row 1+ 4 (row 7)

[ ][ ]
8 0 −4 0 0 0 −2 2√3 0 0 0
0 12 0 0 0 0 2√3 −6 0 0 −4 x 10
−3

−4 0 12 0 −4 0 −2 −2 √ 3 −2 2√ 3 0
0 0 0 12 0 0 −2 √ 3 −6 2 √3 −6 −4 x 10
−3

0 0 −4 0 8 0 0 0 −2 −2 √ 3 0
0 0 0 0 0 12 0 0 −2 √3 −6 −4 x 10−3
0 8 √ 3 −12 −8 √ 3 0 0 46 2√3 −16 0 0
−3
0 0 −4 √ 3 −12 0 0 12 √ 3 12 −4 √ 3 0 −4 x 10
0 0 −2 2 √3 −2 −2 √ 3 −4 0 12 0 0
0 0 2 √3 −2 √ 3 −2 √ 3 −6 0 0 0 12 −4 x 10−3
Result when the values below the pivot in column 1 and column 2 are eliminated:

[ ][ ]
row 1−row 5

8 0 −4 0 0 0 −2 2√ 3 0 0 0
0 12 0 0 0 0 2√ 3 −6 0 0 −4 x 10
−3

0 0 20 0 −8 0 −6 −2 √ 3 −4 4 √3 0
0 0 0 12 0 0 −2 √3 −6 2 √ 3 −6 −4 x 10
−3

0 0 0 0 −8 0 −2 2√ 3 2 2 √3 0
−2 √ 3 −6
−3
0 0 0 0 0 12 0 0 −4 x 10
0 0 144 −96 √ 3 0 0 −504 −72 √ 3 192 0 −0.05542562584
0 0 −4 √ 3 −12 0 0 12 √ 3 12 −4 √3 0 −4 x 10−3
0 0 −2 2 √3 −2 −2 √ 3 −4 0 12 0 0
0 0 2 √ 3 −2 √ 3 −2 √ 3 −6 0 0 0 12 −4 x 10−3

Final result of the elimination:

[ ][ ]
8 0 −4 0 0 0 −2 2 √3 0 0 0
0 12 0 0 0 0 2√ 3 −6 0 0 −4 x 10
−3

0 0 20 0 −8 0 −6 −2 √ 3 −4 4 √3 0
0 0 0 12 0 0 −2 √3 −6 2√ 3 −6 −4 x 10
−3

0 0 0 0 −8 0 −2 2 √3 2 2 √3 0
−2 √3
−3
0 0 0 0 0 12 0 0 −6 −4 x 10
0 0 0 0 0 0 −624 −48 √ 3 240 −48 √ 3 −.1108512517
0 0 0 0 0 0 0 36 10 √3 −42 −0.032
0 0 0 0 0 0 0 0 23040 −103756.7716 −46.55752569
0 0 0 0 0 0 0 0 0 537079.7038 −791.0278392

After getting the final matrix, write the equation starting below the matrix and then solve for the value.
Note that the values of X1-10 in manual calculation here and the python program are not the same, because there
will be discrepancies caused by rounding off.

537079.7038 x10=−791.0278392
−3
−3
xx1010=−1.4728
=−1.4728 xx10
10
23040 x 9−103756.7716 x10 =−46.55752569

−3
x 9=4.6119 x 10

36 x 8−10 √ 3 x 9 −42 x10=−0.032

−3
x 8=−3.618 9 x 10

−624 x 7−−48 √ 3 x 8 +240 x 9−48 √ 3 x 10=−0.110852517

−6
x 7=4.9 403 x 10

12 x6 −2 √ 3 x 7−6 x 10=−4 x 10−3

x 6=−1 . 734 3 x 10−3

−8 x 5−2 x7 −2 √ 3 x 8 +2 x 9 +2 √ 3=0

−4
x 5=−8 . 6 343 x 10

12 x 4−2 √ 3 x 7−6 x8 +2 √ 3 x 9 −6 x 10

−3
x 4 =−2. 9962 x 10
20 x 3−8 x 5−6 x 7−2 √ 3 x 8 −4 x 9 +4 √3 x 10=0

−4
x 3=−1 . 8012 x 10

12 x2 +2 √ 3 x 7−6 x8 =−4 x 10
−3

x 2=−2 . 5812 x 10−3

8 x 1−4 x3 −2 x 7 +2 √3 x 8=0

−3
x 1=1 . 9872 x 10

3. Problems Encountered

When coding the main program there is an error in array “TypeError: only size-1 arrays can be
converted to Python scalars solution”. I found the function np.linalg in numpy. After inputing that function, the
code successfully run.

4. References

mechtutor com. (2019b, November 20). Gauss Elimination Method Tutorial - Part 1and Part 2: Basic

Procedure | Numerical Methods with Python [Video].


5. Appendix

The same code is located in notepad (Assign2_code)

print("-----Displacement of the Each Members of the Given Truss Solver by Gaussian Elimination-----")

print("#NOTE: In the problem, the given are:")

print("-----A(1-5)= 1 in^2; A(6-11)= 2 in^2")

print("-----P(odd)= 0lb; P(even)= -1000lb")

print("-----E= 30psi; l= 30in")

import numpy as np

import math

print("Input Value")

a = float(input("Enter Value of A(1-5) in square inch: "))

b =float(input("Enter Value of A(6-11)in square inch: "))

P1 = P3 = P5 = P7 = P9 =float(input("Enter Value of P(odd) in lb: "))

P2 = P4 = P6 = P8 = P10 = float(input("Enter Value of P(even) in lb: "))

E = float(input("Enter Value of Modulus of Elasticity (x10^6) in psi: "))

E = E*10**6

l = float(input("Enter length of the member (l) in inches: "))

A =np.array([[((4*a)+(b)+(b)), ((math.sqrt(3))*(b-b)), ((-4)*(a)), 0, 0, 0, (-b),((math.sqrt(3))*(b)), 0, 0 ],

[((math.sqrt(3))*(b-b)), ((3)*(b+b)), 0, 0, 0, 0, ((math.sqrt(3))*(b)),((-3)*(b)), 0, 0 ],

[((-4)*(a)), 0, (((4)*(a))+ (((4)*(a)))+(b)+(b)),((math.sqrt(3))*(b-b)), ((-4)*(a)), 0, ((-b)), (-


(math.sqrt(3))*(b)), ((-b)), ((math.sqrt(3))*(b))],

[0, 0, ((math.sqrt(3))*(b-b)), ((3)*(b+b)), 0, 0, (-(math.sqrt(3))*(b)), ((-3)*(b)), ((math.sqrt(3))*(b)),((-


3)*(b))],
[0, 0, ((-4)*(a)), 0, ((4*a)+(b)+(b)), ((math.sqrt(3))*(b-b)), 0, 0, ((-b)), (-(math.sqrt(3))*(b))],

[0, 0, 0, 0, ((math.sqrt(3))*(b-b)),((3)*(b+b)), 0, 0, (-(math.sqrt(3))*(b)), ((-3)*(b))],

[((-b)), ((math.sqrt(3))*(b)), ((-b)),(-(math.sqrt(3))*(b)), 0, 0, (((4)*(a))+ (((4)*(a)))+(b)+(b)), (-


(math.sqrt(3))*(b-b)), ((-4)*(a)),0],

[((math.sqrt(3))*(b)), ((-3)*(b)),(-(math.sqrt(3))*(b)), ((-3)*(b)), 0, 0, (-(math.sqrt(3))*(b-b)), ((3)*(b+b)),


0, 0],

[0, 0, ((-b)), ((math.sqrt(3))*(b)), ((-b)), (-(math.sqrt(3))*(b)), ((-4)*(a)), 0, ((4)*(a))+ (((4)*(a)))+(b)+(b),


(-(math.sqrt(3))*(b-b))],

[0, 0, ((math.sqrt(3))*(b)), (-(math.sqrt(3))*(b)), (-(math.sqrt(3))*(b)), ((-3)*(b)), 0, 0, (-(math.sqrt(3))*(b-


b)), ((3)*(b+b))]])

b = np.array([((4*l)/E)*P1, ((4*l)/E)*P2, ((4*l)/E)*P3, ((4*l)/E)*P4, ((4*l)/E)*P5, ((4*l)/E)*P6, ((4*l)/E)*P7,


((4*l)/E)*P8, ((4*l)/E)*P9, ((4*l)/E)*P10])

print("The values of X1 to X10 is:")

x = np.linalg.solve(A, b)

print(x)

print("All answers are in inches")

You might also like