import numpy as np
import matplotlib.pyplot as plt
Import
학습 목표
- \(PA = LU\)
- Vector spaces and subspaces
-
Permutation P: execute row exchanges 행 교환을 실행하는 행렬인 치환행렬
- P = Identity matrix with reordered rows
\(A = Lu = \begin{bmatrix} 1 & 0 & 0 & 0 \\ x & 1 & 0 & 0 \\ x & x & 1 & 0 \\ x & x & x & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}\)
- 위에서 아무런 행동할 필요없어서 단위행렬을 곱해준 것이고, 여기서 단위행렬이 \(P\)행렬이 된다.
- 결국 \(PA = Lu\)
- 여기서 모든 invertible \(A\)가 가능하다.
- P는 총 \(n!\)개 가질 수 있음
- = counts reorderings
- = counts all \(n \times n\) permutations
- \(P^{-1} = P^T\), \(P^TP = I\)
-
Transpose
\(\begin{bmatrix} 1 & 3 \\ 2 & 3 \\ 4 & 1\end{bmatrix}^T = \begin{bmatrix} 1 & 2 & 4 \\ 3 & 3 & 1 \end{bmatrix}\)
- \((A^T)_{ij} = A_{ji}\)
-
Symmetric matrices
\(A^T = A\)
ex) \(\begin{bmatrix} 3 & 1 & 7 \\ 1 & 2 & 9 \\ 7 & 9 & 4\end{bmatrix}\)
\(R^T R\) is always symmetric.
- 증명: \((R^T R)^T = R^T R^{TT}\)
ex) \(\begin{bmatrix} 1 & 3 \\ 2 & 3 \\ 4 & 1\\\end{bmatrix} \begin{bmatrix} 1 & 2 & 4 \\ 3 & 3 & 1 \end{bmatrix} = \begin{bmatrix} 10 & 11 & 7 \\ 11 & - & - \\ 7 & - & - \end{bmatrix}\)
-
Vector Spaces
\(R^2\) = real number = all 2-dimensional real vectors = x-y plane
ex) \(\begin{bmatrix} 3 \\ 2 \end{bmatrix} \begin{bmatrix} 0 \\ 0 \end{bmatrix} \begin{bmatrix} \pi \\ e\end{bmatrix}\)
every vector has zero vector
# 벡터 정의
= np.array([3, 2])
v1 = np.array([0, 0])
v2 = np.array([np.pi, np.e])
v3 = np.array([-3, -2])
v4
# 그림 설정
plt.figure()
# 원점에서 벡터 v1을 시작하여 그림
0, 0, v1[0], v1[1], angles='xy', scale_units='xy', scale=1, color='r', label='1st component')
plt.quiver(
# 원점에서 벡터 v2을 시작하여 그림 (영벡터이므로 표시하지 않음)
0, 0, v2[0], v2[1], angles='xy', scale_units='xy', scale=1, color='b', label='Z')
plt.quiver(
# 원점에서 벡터 v3을 시작하여 그림
0, 0, v3[0], v3[1], angles='xy', scale_units='xy', scale=1, color='g', label='2nd component')
plt.quiver(
0, 0, v4[0], v4[1], angles='xy', scale_units='xy', scale=1, color='m', label='3nd component')
plt.quiver(
# 축 범위 설정
-3, 8)
plt.xlim(-3, 3)
plt.ylim(
# 축 표시
0, color='k', linewidth=0.5)
plt.axhline(0, color='k', linewidth=0.5)
plt.axvline(
# 그리드 표시
True, linestyle='--', linewidth=0.5)
plt.grid(
# 벡터 표시
'x')
plt.xlabel('y')
plt.ylabel(
# 벡터 레이블 표시
plt.legend()
# 그림 보이기
plt.show()
\(R^3\) = all column vectors with 3 real components
\(\begin{bmatrix} 3 \\ 2 \\ 0 \end{bmatrix}\)이것은 \(R^3\)! \(R^2\) 아님!
\(R^n\) = all column vectors with N real components
not a vector space
아래는 \(\frac{1}{4}\) 영역임
it is not closed under multiplication by all real number
# 사각형의 꼭짓점 좌표
= [0, 0, 3, 3, 0]
x = [0, 3, 3, 0, 0]
y
# 사각형을 그림
='blue', alpha=0.5)
plt.fill(x, y, color
# 축 범위 설정
-3, 3)
plt.xlim(-3, 3)
plt.ylim(
# 축 표시
0, color='k', linewidth=0.5)
plt.axhline(0, color='k', linewidth=0.5)
plt.axvline(
# 그래프 표시
True)
plt.grid('equal', adjustable='box')
plt.gca().set_aspect( plt.show()
ex) a vector space inside \(R^2\) = subspace of \(R^2\)
- double vector 등 any vector is ok.
- multiple 가능해야 함 (곱해서 벡터를 나타낼 수 있어야 함(?))
- line in \(R^2\) through zero vector. \(\begin{bmatrix} 0 \\ 0\end{bmatrix}\) 통과해야 함.
# 벡터 정의
= np.array([3, 2])
v1 = np.array([0, 0])
v2 = np.array([np.pi, np.e])
v3 = np.array([-3, -2])
v4
# 그림 설정
plt.figure()
# 원점에서 벡터 v1을 시작하여 그림
0, 0, v1[0], v1[1], angles='xy', scale_units='xy', scale=1, color='b', label='1st component')
plt.quiver(
# 원점에서 벡터 v2을 시작하여 그림 (영벡터이므로 표시하지 않음)
0, 0, v2[0], v2[1], angles='xy', scale_units='xy', scale=1, color='b', label='Z')
plt.quiver(
# 원점에서 벡터 v3을 시작하여 그림
0, 0, v4[0], v4[1], angles='xy', scale_units='xy', scale=1, color='b', label='3nd component')
plt.quiver(
# 축 범위 설정
-3, 3)
plt.xlim(-3, 3)
plt.ylim(
# 축 표시
0, color='k', linewidth=0.5)
plt.axhline(0, color='k', linewidth=0.5)
plt.axvline(
# 그리드 표시
True, linestyle='--', linewidth=0.5)
plt.grid(
# 벡터 표시
'x')
plt.xlabel('y')
plt.ylabel(
# 그림 보이기
plt.show()
-
subspaces of \(R^2\)
- all of \(R^2\)
- any line through \(\begin{bmatrix} 0 \\ 0 \end{bmatrix}\) \(\to\) \(L\)
- zero vector only \(Z\)
\(\begin{bmatrix} 1 & 3 \\ 2 & 3 \\ 4 & 1 \end{bmatrix}\)
- columns in \(R^3\)
- all their combinations from a subspace
- called column space \(C(A)\)
- plane = \(C(A)\) = all vectors \(Av\)
- 이떄, \(Av\) = \(v_1\begin{bmatrix} 1 \\ 2 \\ 4 \end{bmatrix} v_2 \begin{bmatrix} 3 \\ 3 \\ 1 \end{bmatrix}\)
위에서 column 1, column 2로 나눠 보기
\(\to\) column space로 subspace보기 가능
- The column space consists of all combination of the columns
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 주어진 행렬
= np.array([[1, 3],
matrix 2, 3],
[4, 1]])
[
# 행렬을 열 벡터로 분할
= matrix[:, 0]
column1 = matrix[:, 1]
column2 = np.zeros_like(column1) # z 축은 0으로 고정
zeros
# 3차원 그래프 생성
= plt.figure()
fig = fig.add_subplot(111, projection='3d')
ax
# 열 벡터를 그래프에 추가
='o')
ax.plot(column1, column2, zeros, marker
# 그래프에 라벨 추가
'X Axis')
ax.set_xlabel('Y Axis')
ax.set_ylabel('Z Axis')
ax.set_zlabel(
'Vectors in 3D Space')
plt.title( plt.show()
참고 가능: https://math.mit.edu/~gs/dela/dela_5-1.pdf