-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometric_SVD.py
More file actions
41 lines (29 loc) · 1.13 KB
/
Copy pathGeometric_SVD.py
File metadata and controls
41 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
import matplotlib.pyplot as plt
theta = np.linspace(0, 2 * np.pi, 100)
x = np.cos(theta)
y = np.sin(theta)
A = np.array([[2, 1], [0, 2]])
U, S, Vt = np.linalg.svd(A)
circle_points = np.vstack((x, y))
transformed_points = A @ circle_points
plt.figure(figsize=(10, 5))
plt.plot(transformed_points[0, :], transformed_points[1, :], label='Elipse (AS)', color='orange')
plt.plot(x, y, label='Círculo Unitário', color='blue', linestyle='--')
vector_u1 = S[0] * U[:, 0]
vector_u2 = S[1] * U[:, 1]
plt.plot([0, vector_u1[0]], [0, vector_u1[1]], color='red', label='sigma_1 * u_1')
plt.plot([0, vector_u2[0]], [0, vector_u2[1]], color='green', label='sigma_2 * u_2')
# Vetor v1 (primeira linha de Vt)
plt.plot([0, Vt[0, 0]], [0, Vt[0, 1]], color='blue', label='v1')
# Vetor v2 (segunda linha de Vt)
plt.plot([0, Vt[1, 0]], [0, Vt[1, 1]], color='green', label='v2')
plt.title('Transformação Linear e Decomposição SVD')
plt.xlabel('Eixo X')
plt.ylabel('Eixo Y')
plt.axhline(0, color='black', linewidth=0.5, linestyle='--')
plt.axvline(0, color='black', linewidth=0.5, linestyle='--')
plt.grid()
plt.axis('equal')
plt.legend()
plt.show()