Created
February 25, 2024 15:49
-
-
Save fpaupier/1582e7e4f649fecd3aa6c18023cb2507 to your computer and use it in GitHub Desktop.
Generate figures of vector space generated from the columns of two 3-dimensions matrix with rank = 3 and rank = 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def main() -> None: | |
# Define the matrices | |
W1 = np.eye(3) # Identity matrix | |
W2 = np.array([[3, -2, 1], [2, -2, 0], [0, 1, 1]]) # Rank-deficient matrix | |
# Create figure for W1 | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
origin = [0, 0, 0] | |
ax.quiver(*origin, W1[:, 0], W1[:, 1], W1[:, 2], color=['b', 'g', 'r']) | |
ax.set_xlim([-1, 2]) | |
ax.set_ylim([-1, 2]) | |
ax.set_zlim([-1, 2]) | |
ax.set_title('Vector Space Generated by W1 (r = 3)') | |
plt.show() | |
# Create figure for W2 | |
fig, ax = plt.subplots() | |
ax.quiver(0, 0, W2[0, 0], W2[1, 0], angles='xy', scale_units='xy', scale=1, color='b', label='C1') | |
ax.quiver(0, 0, W2[0, 1], W2[1, 1], angles='xy', scale_units='xy', scale=1, color='g', label='C2') | |
ax.quiver(0, 0, W2[0, 2], W2[1, 2], angles='xy', scale_units='xy', scale=1, color='r', | |
label='C3 - Linear Combination of C1 and C2') | |
ax.set_xlim([-3, 4]) | |
ax.set_ylim([-3, 4]) | |
ax.set_aspect('equal') | |
ax.set_title('Vector Space Generated by W2 (r = 2)') | |
ax.legend() | |
plt.show() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment