The linear algebra that you will definitely learn at a science university is summarized in an easy-to-understand and logical manner. By the way, I implemented it in Python. Occasionally, it may be implemented in Julia. .. .. ・ Learn by running with Python! New Mathematics Textbook-Basic Knowledge Required for Machine Learning / Deep Learning- ・ World Standard MIT Textbook Strang Linear Algebra Introduction Understand linear algebra based on and implement it in python.
・ Jupyter Notebook ・ Language: Python3, Julia 1.4.0
It is a linear combination
av + bw
Speak based on the shape of. The vectors v and w need to have different direction vectors. For example
\vec{v}=\begin{pmatrix}2\\3\end{pmatrix}
,
\vec{w}=\begin{pmatrix}1\\-2\end{pmatrix}
It is a relationship like. This means that, as we did last time, the two vectors form an angle that does not satisfy nπ (n = 0, 1, 2, ...). That is,
\vec{v}=\begin{pmatrix}2\\3\end{pmatrix}
,
\vec{w}=\begin{pmatrix}4\\6\end{pmatrix}
\\
\\
\vec{v}=α\vec{w}
As shown above, the scalar product relation and multiple relation are called linear dependence
. It is called what is not linear independence
. Each must be independent, even three, not two.
In the image, it should look like this.
Definition </ font> When Ax = 0 has only x = 0, the column vector is a linear algebra. No other linear combination Ax of column vectors is a zero vector. The vector columns v_1, v_2, ...., v_n have a linear combination that is a zero vector.
0v_1+0v_2+...+0v_n
When only, it is linearly independent.
That is,
All x_Only when i is zero,\\
x_1v_1+x_2v_2+...+x_nv_n=0\\
Becomes.
When this does not happen, it is called linear dependence.
6pythonlinearindependece
import numpy as np
v = list()
w = list()
for i in range(2):
vbec = int(input())
v.append(vbec)
for i in range(2):
wbec = int(input())
w.append(wbec)
v = np.array(v)
w = np.array(w)
sarrus = v[0]*v[1] - v[1]*v[0]
if sarrus == 0:
print("Linear dependency")
else:
print("Linear independence")
I tried linear algebra in Python (2)にあるコードを少しだけ書き換えたものである。 This can only be determined if the vectors have two elements. The program that first counts the number of elements and determines whether it is independent or dependent is as follows.
6pythonlinearindependece2
import numpy as np
n = int(input())
# =>3
v = list()
w = list()
for i in range(n):
vbec = int(input())
v.append(vbec)
for i in range(n):
wbec = int(input())
w.append(wbec)
v = np.array(v)
w = np.array(w)
# =>1
# =>2
# =>3
# =>3
# =>2
# =>1
x = list()
c = v[0]/w[0]
for i in range(n):
if v[i] == c*w[i]:
x.append("True")
continue
else:
break
if len(x) == n:
print("Linear dependency")
elif len(x) < n:
print("Linear independence")
# =>Linear independence
Definition </ font>
The basis of a vector space is a sequence of vectors that has the following two properties: *** Basis vectors are linearly independent and span a space. ***
I will omit a detailed explanation of the basis here.
Concrete example
I =
\begin{bmatrix}
1 & 0\\
0 & 1
\end{bmatrix}
Column vector is R^2 standard basis.
From this, it can be said as follows.
(n×n)The column vector of the identity matrix is R^is the "standard basis" of n.
further,
All(n×n)The column vector of the matrix is R^is the "standard basis" of n
The dimensions are also omitted here.
\vec{e_x}=\begin{pmatrix}1\\0\end{pmatrix},
\vec{e_y}=\begin{pmatrix}0\\1\end{pmatrix}
Then, a = (2,3) can be expressed as follows.
\vec{a}=\begin{pmatrix}2\\3\end{pmatrix}=2\vec{e_x}+3\vec{e_y}
=2\begin{pmatrix}0\\1\end{pmatrix}+3\begin{pmatrix}1\\0\end{pmatrix}
Than this
\vec{a},\vec{e_x},\vec{e_y}
Draw three vectors of. I tried linear algebra with Python (5) It's not new because it has 3 vectors ver.
import numpy as np
import matplotlib.pyplot as plt
a = np.array([2, 3])
e_x = np.array([1, 0])
e_y = np.array([0, 1])
print("a:", a)
print("e_x:", e_x)
print("e_y:", e_y)
def arrow(start, size, color):
plt.quiver(start[0], start[1], size[0], size[1],
angles="xy", scale_units="xy", scale=1, color=color)
s = np.array([0, 0]) #origin
arrow(s, a, color="blue")
arrow(s, e_x, color="red")
arrow(s, e_y, color="red")
#graph display
plt.xlim([-3,3]) #Display range of x
plt.ylim([-3,3]) #Display range of y
plt.xlabel("x", size=14)
plt.ylabel("y", size=14)
plt.grid()
plt.axes().set_aspect("equal") #Same aspect ratio
plt.show()
I haven't done that difficult. For python, I'm writing a little detour code. (To make the principle easier to understand) I can't draw graphs in julia (?), So I'll write code in the field of calculations.
Recommended Posts