我有一个方程如下:
y = x^T * A * x + b^T * x + c
其中 x, b, c 是 n 空间中的向量,A 是 nxn 矩阵。
我可以在 matplotlib 中绘制线性方程,但不确定矩阵方程如何(如果可能)也显示在 3d 图中。
我尝试使用以下代码,A 是矩阵,w、c 和 b 是列向量。X 和 Y 是网格,Z 是解。
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
# if using a Jupyter notebook, include:
%matplotlib inline
fig = plt.figure(figsize=(10,6))
ax1 = fig.add_subplot(111, projection='3d')
n = 50
i = -5.0
j = 5.0
A = np.random.randint(i, j, size=(n, n))
w = np.random.randint(i, j, size=(n, 1))
c = b = np.random.randint(i, j, size=(n, 1))
X,Y = np.meshgrid(n,n)
Z = w.T*A*w + b.T*w + c
mycmap = plt.get_cmap('gist_earth')
surf1 = ax1.plot_surface(X, A, Z, cmap=mycmap)
fig.colorbar(surf1, ax=ax1, shrink=0.5, aspect=10)
plt.show()
由此产生的情节似乎不是一个令人满意的情节。
