<jupyter_start><jupyter_text>To find the inverse of a matrix, the matrix is passed to the linalg.inv() of the NumPy module: Solve a system of two linear equations shown below:4x + 3y = 20-5x + 9y = 26<jupyter_code>import numpy as np
A = np.array([[4,3],[-5,9]])
print(A)
print("------------")
inv_A =np.linalg.inv(A)
print(inv_A)
print("------------")
B = np.array([[20],[26]])
X=np.linalg.inv(A).dot(B) #method in solving values of unknown var.
print(X)
print("------------")
X=np.dot(inv_A,B) #alternative method in solving values of unknown var.
print(X)<jupyter_output>[[ 4  3]
 [-5  9]]
------------
[[ 0.17647059 -0.05882353]
 [ 0.09803922  0.07843137]]
------------
[[2.]
 [4.]]
------------
[[2.]
 [4.]]<jupyter_text>Let's now solve a system of three linear equations shown below:4x + 3y + 2z = 25-2x + 2y + 3z = -103x - 5y + 2z = -4<jupyter_code>import numpy as np
A = np.array([[4,3,2],[-2,2,3],[3,-5,2]]) #creation of matrix A
print(A)
print("------------")
inv_A = np.linalg.inv(A) #inverse of matrix A
print(inv_A)
print("------------")
B = np.array([[25],[-10],[-4]]) #creation of matrix B (constants of the eq.)
print(B)
print("------------")
X = np.dot(inv_A,B) #dot product (values of x,y,z)
print(X)<jupyter_output>[[ 4  3  2]
 [-2  2  3]
 [ 3 -5  2]]
------------
[[ 0.15447154 -0.1300813   0.04065041]
 [ 0.10569106  0.01626016 -0.1300813 ]
 [ 0.03252033  0.23577236  0.11382114]]
------------
[[ 25]
 [-10]
 [ -4]]
------------
[[ 5.]
 [ 3.]
 [-2.]]<jupyter_text>APPLICATION (ORANGE AND APPLE)<jupyter_code>import numpy as np
A = np.array([[20,10],[17,22]])
print(A)
print("------------")
inv_A =np.linalg.inv(A)
print(inv_A)
print("------------")
B = np.array([[350],[500]])
X=np.dot(inv_A,B)
print(X)<jupyter_output>[[20 10]
 [17 22]]
------------
[[ 0.08148148 -0.03703704]
 [-0.06296296  0.07407407]]
------------
[[10.]
 [15.]]<jupyter_text>TO CHECK IF THE ANSWER IS CORRECT<jupyter_code>B = np.dot(A,X)
print(B)<jupyter_output>[[350.]
 [500.]]
{'fraction_non_alphanumeric': 0.2868020304568528, 'fraction_numerical': 0.12791878172588833, 'mean_word_length': 2.718867924528302, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '232370', 'license': 'Apache-2.0', 'n_tokens_mistral': 979, 'n_tokens_neox': 841, 'n_words': 194, 'path': 'DEMO_2_(LINEAR_TRANSFORMATION).ipynb', 'repo_name': 'viaa-bot/Linear-Algebra-58019', 'size': '1970'}