考虑 R ^2 中的两个向量 u 和 v,它们彼此独立,即不指向相同或相反的方向。因此,R ^2 中的任何向量都可以用 u 和 v 的线性组合来表示。例如,这是一个线性组合,本质上是一个线性系统。
fig, ax = plt.subplots(figsize=(8, 8))
vectors = np.array(
[[[0, 0, 4, 2]], [[0, 0, -2, 2]], [[0, 0, 2, 10]], [[0, 0, 8, 4]], [[0, 0, -6, 6]]]
)
colors = ["b", "b", "r", "b", "b"]
for i in range(vectors.shape[0]):
X, Y, U, V = zip(*vectors[i, :, :])
ax.quiver(
X, Y, U, V, angles="xy", scale_units="xy", color=colors[i], scale=1, alpha=0.6
)
ax.text(
x=vectors[i, 0, 2],
y=vectors[i, 0, 3],
s="$(%.0d, %.0d)$" % (vectors[i, 0, 2], vectors[i, 0, 3]),
fontsize=16,
)
points12 = np.array([[8, 4], [2, 10]])
ax.plot(points12[:, 0], points12[:, 1], color="b", lw=3.5, alpha=0.5, ls="--")
points34 = np.array([[-6, 6], [2, 10]])
ax.plot(points34[:, 0], points34[:, 1], color="b", lw=3.5, alpha=0.5, ls="--")
ax.set_xlim([-10, 10])
ax.set_ylim([0, 10.5])
ax.set_xlabel("x-axis", fontsize=16)
ax.set_ylabel("y-axis", fontsize=16)
ax.grid()
a = np.arange(-11, 20, 1)
x = np.arange(-11, 20, 1)
for i in a:
y1 = i + 0.5 * x
ax.plot(x, y1, ls="--", color="pink", lw=2)
y2 = i - x
ax.plot(x, y2, ls="--", color="pink", lw=2)
ax.set_title(
r"Linear Combination of Two Vectors in $\mathbf{R}^2$", size=22, x=0.5, y=1.01
)
plt.show()
def linearCombo(a, b, c):
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection="3d")
vec = np.array(
[
[[0, 0, 0, 1, 0, 0]],
[[0, 0, 0, 0, 1, 0]],
[[0, 0, 0, 0, 0, 1]],
[[0, 0, 0, a, 0, 0]],
[[0, 0, 0, 0, b, 0]],
[[0, 0, 0, 0, 0, c]],
[[0, 0, 0, a, b, c]],
]
)
colors = ["b", "b", "b", "r", "r", "r", "g"]
for i in range(vec.shape[0]):
X, Y, Z, U, V, W = zip(*vec[i, :, :])
ax.quiver(
X,
Y,
Z,
U,
V,
W,
length=1,
normalize=False,
color=colors[i],
arrow_length_ratio=0.08,
pivot="tail",
linestyles="solid",
linewidths=3,
alpha=0.6,
)
dlines = np.array(
[
[[a, 0, 0], [a, b, 0]],
[[0, b, 0], [a, b, 0]],
[[0, 0, c], [a, b, c]],
[[0, 0, c], [a, 0, c]],
[[a, 0, c], [a, b, c]],
[[0, 0, c], [0, b, c]],
[[0, b, c], [a, b, c]],
[[a, 0, 0], [a, 0, c]],
[[0, b, 0], [0, b, c]],
[[a, b, 0], [a, b, c]],
]
)
colors = ["k", "k", "g", "k", "k", "k", "k", "k", "k"]
for i in range(dlines.shape[0]):
ax.plot(
dlines[i, :, 0],
dlines[i, :, 1],
dlines[i, :, 2],
lw=3,
ls="--",
color="black",
alpha=0.5,
)
ax.text(x=a, y=b, z=c, s=" $(%0.d, %0.d, %.0d)$" % (a, b, c), size=18)
ax.text(x=a, y=0, z=0, s=" $%0.d e_1 = (%0.d, 0, 0)$" % (a, a), size=15)
ax.text(x=0, y=b, z=0, s=" $%0.d e_2 = (0, %0.d, 0)$" % (b, b), size=15)
ax.text(x=0, y=0, z=c, s=" $%0.d e_3 = (0, 0, %0.d)$" % (c, c), size=15)
ax.grid()
ax.set_xlim([0, a + 1])
ax.set_ylim([0, b + 1])
ax.set_zlim([0, c + 1])
ax.set_xlabel("x-axis", size=18)
ax.set_ylabel("y-axis", size=18)
ax.set_zlabel("z-axis", size=18)
ax.set_title("Vector $(%0.d, %0.d, %.0d)$ Visualization" % (a, b, c), size=20)
ax.view_init(elev=20.0, azim=15)
if __name__ == "__main__":
a = 7
b = 4
c = 9
linearCombo(a, b, c)