<jupyter_start><jupyter_text>Learning the fundamentals of linear algebra through python<jupyter_code>from matrix import Matrix
A = Matrix([[(i_out+1)*(i_in+1) for i_in in range(3)] for i_out in range(3)])
B = Matrix([[(j_in+j_out)**(j_out+1) for j_in in range(3)] for j_out in range(3)])

print('A')
print(A)

print('\n{}\n'.format('-'*40))

print('B')
print(B)
#addition and subtraction between two matrices
print('A + B')
print(A + B)

print('\n{}\n'.format('-'*40))

print('A - B')
print(A - B)<jupyter_output>A + B
[[1.0, 3.0, 5.0]
 [3.0, 8.0, 15.0]
 [11.0, 33.0, 73.0]]

----------------------------------------

A - B
[[1.0, 1.0, 1.0]
 [1.0, 0.0, -3.0]
 [-5.0, -21.0, -55.0]]<jupyter_text>addition and subtraction method for vectors and matrices addition between two vectors$$\boldsymbol{a} + \boldsymbol{b} =    \left[\begin{array}{ccc}        a_0 + b_0 \\        \vdots \\        a_n + b_n \\    \end{array}\right]$$ subtraction between two vectors$$\boldsymbol{a} - \boldsymbol{b} =    \left[\begin{array}{ccc}    a_0 - b_0 \\    \vdots \\    a_n - b_n \\    \end{array}\right]$$ addition between two matrices$$\boldsymbol{A} + \boldsymbol{B} =    \left[\begin{array}{ccc}        a_{0,0} + b_{0,0} & \cdots & a_{0,m} + b_{0,m} \\        \vdots & \ddots & \vdots \\        a_{n,0} + b_{n,0} & \cdots & a_{n,m} + b_{n,m} \\    \end{array}\right]$$ subtraction between two matrices$$\boldsymbol{A} - \boldsymbol{B} =    \left[\begin{array}{ccc}        a_{0,0} - b_{0,0} & \cdots & a_{0,m} - b_{0,m} \\        \vdots & \ddots & \vdots \\        a_{n,0} - b_{n,0} & \cdots & a_{n,m} - b_{n,m} \\    \end{array}\right]$$ ::::: Note :::::- When calculating the sum/difference of multiple vectors or matrices, the size of both vectors or matrices must match in order to calculate the addition/subtraction between the vectors or matrices.<jupyter_code>#multiplication between a scalar and matrix
scalar = -0.1

print('-1 x (A + B)')
print(scalar * (A + B))<jupyter_output>-1 x (A + B)
[[-0.1, -0.3, -0.5]
 [-0.3, -0.8, -1.5]
 [-1.1, -3.3, -7.3]]<jupyter_text>Scalar multiplication for vectors and matrices multiplication between a scalar and vectors$$\boldsymbol{s} \times \boldsymbol{a} =    \left[\begin{array}{ccc}        s \times a_0 \\        \vdots \\        s \times a_n \\    \end{array}\right]$$ multiplication between a scalar and matrices$$\boldsymbol{s} \times \boldsymbol{A} =    \left[\begin{array}{ccc}        s \times a_{0,0} & \cdots & s \times a_{0,m} \\        \vdots & \ddots & \vdots \\        s \times a_{n,0} & \cdots & s \times a_{n,m} \\    \end{array}\right]$$<jupyter_code>#transpose of a matrix
B_T = Matrix(B.matrix)

print('original matrix B')
print(B_T)

print('\n{}\n'.format('-'*40))

print('transposed matrix B')
B_T.T()
print(B_T)<jupyter_output>original matrix B
[[0.0, 1.0, 2.0]
 [1.0, 4.0, 9.0]
 [8.0, 27.0, 64.0]]

----------------------------------------

transposed matrix B
[[0.0, 1.0, 8.0]
 [1.0, 4.0, 27.0]
 [2.0, 9.0, 64.0]]<jupyter_text>Transpose of vectors and matrices transpose of a vector$$\boldsymbol{a^T} =    \left[\begin{array}{ccc}        a_0 \\        \vdots \\        a_n \\    \end{array}\right]^T =     \left[\begin{array}{ccc}        a_0 & \cdots & a_n \\    \end{array}\right]$$ transpose of a matrix$$\boldsymbol{A^T} =    \left[\begin{array}{ccc}        a_{0,0} & \cdots & a_{0,m} \\        \vdots & \ddots & \vdots \\        a_{n,0} & \cdots & a_{n,m} \\    \end{array}\right]^T =    \left[\begin{array}{ccc}        a_{0,0} & \cdots & a_{n,0} \\        \vdots & \ddots & \vdots \\        a_{0,m} & \cdots & a_{n,m} \\    \end{array}\right]$$<jupyter_code>#multiplication between two matrices
print('A x B')
print(A * B)

print('\n{}\n'.format('-'*40))

print('B x A')
print(B * A)<jupyter_output>A x B
[[26.0, 90.0, 212.0]
 [52.0, 180.0, 424.0]
 [78.0, 270.0, 636.0]]

----------------------------------------

B x A
[[8.0, 16.0, 24.0]
 [36.0, 72.0, 108.0]
 [254.0, 508.0, 762.0]]<jupyter_text>Multiplication method for vectors and matrices multiplication between vectors$$\boldsymbol{a} =    \left[\begin{array}{ccc}        a_0 & \cdots & a_n \\    \end{array}\right], \boldsymbol{b} =    \left[\begin{array}{ccc}        b_0 \\        \vdots \\        b_n \\    \end{array}\right]$$$$\boldsymbol{a} \times \boldsymbol{b} =    \left[\begin{array}{ccc}        a_0 \times b_0 & \cdots & a_0 \times b_n \\        \vdots & \ddots & \vdots \\        a_n \times b_0 & \cdots & a_n \times b_n \\    \end{array}\right]$$$$\boldsymbol{b} \times \boldsymbol{a} =     \sum^{n}_{i=0}a_i \times b_i$$ multiplication between matrices$$\boldsymbol{A} =    \left[\begin{array}{ccc}        a_{0,0} & \cdots & a_{0,p} \\        \vdots & \ddots & \vdots \\        a_{m,0} & \cdots & a_{m,p} \\    \end{array}\right], \boldsymbol{B} =    \left[\begin{array}{ccc}        b_{0,0} & \cdots & b_{0,n} \\        \vdots & \ddots & \vdots \\        b_{q,0} & \cdots & b_{q,n} \\    \end{array}\right]$$$$\boldsymbol{A} \times \boldsymbol{B} =    \left[\begin{array}{ccc}        \sum^{m}_{i=0}a_{i,0} \times b_{0,i} & \cdots & \sum^{m}_{i=0}a_{i,p} \times b_{0,i} \\        \vdots & \ddots & \vdots \\        \sum^{m}_{i=0}a_{i,0} \times b_{q,i} & \cdots & \sum^{m}_{i=0}a_{i,p} \times b_{q,i} \\    \end{array}\right](n=m)$$$$\boldsymbol{B} \times \boldsymbol{A} =    \left[\begin{array}{ccc}        \sum^{p}_{j=0}b_{j,0} \times a_{0,j} & \cdots & \sum^{p}_{j=0}b_{j,0} \times a_{m,j} \\        \vdots & \ddots & \vdots \\        \sum^{p}_{j=0}b_{j,0} \times a_{m,j} & \cdots & \sum^{p}_{j=0}b_{j,n} \times a_{m,j} \\    \end{array}\right](p=q)$$ ::::: Note :::::1. The vertical length of the first vector/matrix and the horizontal length of the other vector/matrix must match in order to calculate the product of multiple vectors/matrices2. The order of which the vectors/matrices are multiplied will affect the product between the vectors/matrices unlike the addition/subtraction of vectors/matrices.<jupyter_code>#determinant of the two matrices
print('det(A) = {}'.format(A.det()))

print('\n{}\n'.format('-'*40))

print('det(B) = {}'.format(B.det()))<jupyter_output>det(A) = 0.0

----------------------------------------

det(B) = -2.0<jupyter_text>Computation of the determinant of a matrix For matrices with the size 2x2$$\boldsymbol{A} =    \left[\begin{array}{ccc}        a_{0,0} & a_{0,1} \\        a_{1,0} & a_{1,1} \\    \end{array}\right]$$$$det(\boldsymbol{A}) = a_{0,0} \times a_{1,1} - a_{0,1} \times a_{1,0}$$ For matrices with the size above 2x2 Find the triangular matrix of the matrix$$\boldsymbol{A} =    \left[\begin{array}{ccc}        a_{0,0} & \cdots & a_{0,n} \\        \vdots & \ddots & \vdots \\        a_{n,0} & \cdots & a_{n,n}    \end{array}\right],\boldsymbol{U} =    \left[\begin{array}{ccc}        u_{0,0} & 0 & \cdots & 0 \\        0 & u_{1,1} & \cdots & 0 \\        \vdots & \vdots & \ddots & \vdots \\        0 & 0 & \cdots & u_{n,n} \\    \end{array}\right]$$- __A__ is the original matrix, and __U__ is the triangular matrix of __A__. Computation of the determinant After the triangular matrix of __A__ has been computed, the determinant can be solved with the following algebraic expression$$det(\boldsymbol{A}) = \prod^{n}_{i=0,j=0}u_{i,j}$$ ::::: Note :::::- To find the determinant of a matrix, the matrix must be a square matrix<jupyter_code>#Inverse matrix of each matrix
print('1/A')
print(A.inv())

print('\n{}\n'.format('-'*40))

print('1/B')
print(B.inv())<jupyter_output>1/A
This matrix does not have an inverse matrix.
None

----------------------------------------

1/B
Successfully inverted matrix!
[[-9.0, 9.0, -1.0]
 [-9.0, 16.0, -2.0]
 [5.0, -8.0, 1.0]]
{'fraction_non_alphanumeric': 0.23531720078482668, 'fraction_numerical': 0.041334205362982344, 'mean_word_length': 2.581264637002342, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '379945', 'license': 'MIT', 'n_tokens_mistral': 3104, 'n_tokens_neox': 2895, 'n_words': 690, 'path': 'python3/source/linear_algebra.ipynb', 'repo_name': 'bonohub13/linear_algebra', 'size': '7645'}