<jupyter_start><jupyter_text>EQE512 MATRIX METHODS IN STRUCTURAL ANALYSIS ---Week 05 - Visualization of the Parametric Analysis Computations  Dr. <NAME> (<EMAIL>) 2020 Fall   --- **This week :** 1. Matrix Definition2. Matrix in Python3. Matrix Calculations ;     3.1. Summation        3.2. Subtraction        3.3. Multiplication             3.3.1. Dot product                3.3.2. Cross product    3.4. Division        3.5. Inversion        3.6. Transpose        3.7. Determinant      4. Matrix creation    4.1. Zero, one        4.2. Identity matrix        4.3. Diagonal matrix    5. Mass matrix6. Stiffness matrix (how to create in a loop?)7. Visualization---  Matrix Definition_A matrix is a collection of numbers arranged into a fixed number of rows and columns. Usually the numbers are real numbers._  Matrix in PythonMatrix is defined and processed in Numpy module in Python. The variable type is _array_ in Numpy. Do not use currently available "matrix" class because it is deprecated.<jupyter_code>import numpy as np

a = np.array([[1, 2, 4], [4,5,6] , [7,8,9]])

print(a)

b = np.array([[1, 2, 3], 
              [1, 1, 1] , 
              [2, 3, 4]])

print(b)
type(a)
b[2,2]<jupyter_output><empty_output><jupyter_text>Matrix CalculationsThe fundamentals of Matrix operations  Summation<jupyter_code>a + b<jupyter_output><empty_output><jupyter_text>Subtraction<jupyter_code>a - b<jupyter_output><empty_output><jupyter_text>Multiplication<jupyter_code>print( a)
print(b) 
a*b<jupyter_output><empty_output><jupyter_text>Dot product<jupyter_code>np.dot(a,b)<jupyter_output><empty_output><jupyter_text>Cross product<jupyter_code>a*b<jupyter_output><empty_output><jupyter_text>Divison<jupyter_code>print(a)
print("-------")
print(b)
a/b
np.divide(a,b)












np.<jupyter_output><empty_output><jupyter_text>Inversion<jupyter_code>import numpy as np
a_inve = np.linalg.inv( a )
a_inve
# multiply the matrix of a by a_inve

output = np.dot( a , a_inve)

print(output)<jupyter_output>[[ 1.0000000e+00  0.0000000e+00 -4.4408921e-16]
 [ 0.0000000e+00  1.0000000e+00  0.0000000e+00]
 [ 0.0000000e+00  0.0000000e+00  1.0000000e+00]]<jupyter_text>Transpose<jupyter_code>a
a_transpose = np.transpose(a)

print(a_transpose)<jupyter_output>[[1 4 7]
 [2 5 8]
 [4 6 9]]<jupyter_text>Determinant<jupyter_code>np.linalg.det( a)<jupyter_output><empty_output><jupyter_text>Matrix Creation  Special Matrix<jupyter_code>zero_matrix = np.zeros( (4, 4))

print( zero_matrix )
one_matrix = np.ones( (4,5))

print( one_matrix)
999 * np.ones((4,4))<jupyter_output><empty_output><jupyter_text>space "allocation" is important for matrix methods  Identity matrix<jupyter_code>id_matrix = np.eye(4)

print( id_matrix)
9 * id_matrix<jupyter_output><empty_output><jupyter_text>Diagonal matrix<jupyter_code>diag_matrix = np.diag( [1,2,3,4])

print(diag_matrix)<jupyter_output>[[1 0 0 0]
 [0 2 0 0]
 [0 0 3 0]
 [0 0 0 4]]<jupyter_text>Mass Matrix<jupyter_code>mass = np.diag([100,100,100])
print(mass)
mass2 = 100 * np.eye(4)
mass2
mass3 = np.diag( [100 for item in range(4)])
mass3<jupyter_output><empty_output><jupyter_text>Stiffness matrix (how to create in a loop?)<jupyter_code># MEMBER STIFNESS
EI = 100
h = 3
k = 12* EI /(3**3)
print(k)
# STORY STIFFNES
k_story= 2 * k
print(k_story)
k1 = k_story
k2 = k_story
k3 = k_story
# SYSTEM STIFFNESS MATRIX

K = np.array( [[k1+k2 , -k1 ,0 ], 
               [-k1 , k2+k3 , -k2] , 
               [0 , -k2 , k3]])
print(K)<jupyter_output>[[177.77777778 -88.88888889   0.        ]
 [-88.88888889 177.77777778 -88.88888889]
 [  0.         -88.88888889  88.88888889]]<jupyter_text>---<jupyter_code># APPROACH 2
k_stories = [ k1 ,  k2 , k3]
k_stories
K_system = np.eye(3)
K_system
for i in range(3):
    for j in range(3):
        if i == j : 
            K_system[i,j]= k_stories[i] + k_stories[j]
        elif i - j == 1 or  j - i == 1:
            K_system[i,j]= -1* k_stories[i]
        else: 
            K_system[i,j] = 0
K_system[2,2] = k_stories[-1]
K_system<jupyter_output><empty_output><jupyter_text>---What if I have 5 stories building with different stiffnesses at each story?<jupyter_code>k_stories_2 =[10,20,30,40,50,10,20,40]
no_story = len(k_stories_2)
print(no_story)
K_system = np.zeros( (no_story, no_story))
K_system
K_system = np.zeros( (no_story, no_story))
for i in range(no_story-1):
    for j in range( no_story):
        if i == j : 
            K_system[i,j]= k_stories_2[i] + k_stories_2[i+1]
        elif i - j == 1 :
            K_system[i,j]= -1* k_stories_2[j]
        elif j-i == 1:
            K_system[i,j]= -1* k_stories_2[i]
                
        else: 
            K_system[i,j] = 0

K_system[no_story-1,no_story-1] = k_stories_2[-1]
K_system[no_story-1,no_story-2] = -1*k_stories_2[-2]

K_system
np.dot( K_system, np.linalg.inv( K_system))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1357615894039735, 'fraction_numerical': 0.07512417218543047, 'mean_word_length': 3.6786060019361084, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 15, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '67308', 'license': 'MIT', 'n_tokens_mistral': 2190, 'n_tokens_neox': 1983, 'n_words': 428, 'path': '.ipynb_checkpoints/EQE512-Week05-Lecture-checkpoint.ipynb', 'repo_name': 'ahmetanildindar/EQE512-Matrix-Methods-In-Structural-Analysis', 'size': '4854'}