Assignment2 Santos CarlosJoaquin MECp1

Download as pdf or txt
Download as pdf or txt
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𝑥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𝑥10−3
0 0 −4 0 8 0 0 0 −2 −2√3 0
−3
0 0 0 0 0 12 0 0 −2√3 −6 −4𝑥10
−2 2√3 −2 −2√3 0 0 12 0 −4 0 0
−4𝑥10−3
2√3 −6 −2√3 −6 0 0 0 12 0 0
0
0 0 −2 2√3 −2 −2√3 −4 0 12 0 [−4𝑥10−3 ]
[ 0 0 2√3 −2√3 −2√3 −6 0 0 0 12 ]
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(𝑟𝑜𝑤7) + (𝑟𝑜𝑤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𝑥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𝑥10−3
0 0 −4 0 8 0 0 0 −2 −2√3 0
−3
0 0 0 0 0 12 0 0 −2√3 −6 −4𝑥10
−2 2√3 −2 −2√3 0 0 12 0 −4 0 0
−4𝑥10−3
0 0 −4√3 −12 0 0 12√3 12 −4√3 0
0
0 0 −2 2√3 −2 −2√3 −4 0 12 0 [−4𝑥10−3 ]
[0 0 2√3 −2√3 −2√3 −6 0 0 0 12 ]

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.

𝑟𝑜𝑤1 + 4(𝑟𝑜𝑤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𝑥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𝑥10−3
0 0 −4 0 8 0 0 0 −2 −2√3 0
−3
0 0 0 0 0 12 0 0 −2√3 −6 −4𝑥10
0 8√3 −12 −8√3 0 0 46 2√3 −16 0 0
−4𝑥10−3
0 0 −4√3 −12 0 0 12√3 12 −4√3 0
0
0 0 −2 2√3 −2 −2√3 −4 0 12 0 [−4𝑥10−3 ]
[0 0 2√3 −2√3 −2√3 −6 0 0 0 12 ]
Result when the values below the pivot in column 1 and column 2 are eliminated:

𝑟𝑜𝑤1 − 𝑟𝑜𝑤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𝑥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𝑥10−3
0 0 0 0 −8 0 −2 2√3 2 2√3 0
0 0 0 0 0 12 0 0 −2√3 −6 −4𝑥10−3
0 0 144 −96√3 0 0 −504 −72√3 192 0 −0.05542562584
−4𝑥10−3
0 0 −4√3 −12 0 0 12√3 12 −4√3 0
0
0 0 −2 2√3 −2 −2√3 −4 0 12 0 [ −4𝑥10−3 ]
[0 0 2√3 −2√3 −2√3 −6 0 0 0 12 ]

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𝑥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𝑥10−3
0 0 0 0 −8 0 −2 2√3 2 2√3 0
0 0 0 0 0 12 0 0 −2√3 −6 −4𝑥10−3
−.1108512517
0 0 0 0 0 0 −624 −48√3 240 −48√3
−0.032
0 0 0 0 0 0 0 36 10√3 −42 −46.55752569
0 0 0 0 0 0 0 0 23040 −103756.7716 [−791.0278392]
[0 0 0 0 0 0 0 0 0 537079.7038 ]

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𝑥10 = −791.0278392
−3
𝑥𝑥10 −1.4728𝑥10−3
= −1.4728𝑥10
10 =
23040𝑥9 − 103756.7716𝑥10 = −46.55752569

𝑥9 = 4.6119𝑥10−3

36𝑥8 − 10√3𝑥9 − 42𝑥10 = −0.032

𝑥8 = −3.6189𝑥10−3

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

𝑥7 = 4.9403𝑥10−6

12𝑥6 − 2√3𝑥7 − 6𝑥10 = −4𝑥10−3

𝑥6 = −1.7343𝑥10−3

−8𝑥5 − 2𝑥7 − 2√3𝑥8 + 2𝑥9 + 2√3 = 0

𝑥5 = −8.6343𝑥10−4

12𝑥4 − 2√3𝑥7 − 6𝑥8 + 2√3𝑥9 − 6𝑥10

𝑥4 = −2.9962𝑥10−3
20𝑥3 − 8𝑥5 − 6𝑥7 − 2√3𝑥8 − 4𝑥9 + 4√3𝑥10 = 0

𝑥3 = −1.8012𝑥10−4

12𝑥2 + 2√3𝑥7 − 6𝑥8 = −4𝑥10−3

𝑥2 = −2.5812𝑥10−3

8𝑥1 − 4𝑥3 − 2𝑥7 + 2√3𝑥8 = 0

𝑥1 = 1. 9872𝑥10−3

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