【发布时间】:2020-05-25 19:08:29
【问题描述】:
我正在尝试使用以下代码绘制前 20 次迭代的特征值近似图:
def metoda_potegowa(A,X0,iterations):
iteracje=[]
aproks=[]
ii=0
while(1):
for i in range (iterations):
A = A*A
x = A*X0
aproks.append(x)
iteracje.append(ii)
ii=ii+1
norm = np.linalg.norm(x)
plt.scatter(iteracje,aproks)
plt.xlabel('iteracja')
plt.ylabel('aproksymacja')
plt.grid
plt.show
break
print (x/norm)
print (np.linalg.eig(A)[1])
我收到以下警告:
ValueError Traceback (most recent call last)
<ipython-input-96-d18eef58c53a> in <module>()
----> 1 metoda_potegowa(a,x0,5)
4 frames
/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, **kwargs)
4378 y = np.ma.ravel(y)
4379 if x.size != y.size:
-> 4380 raise ValueError("x and y must be the same size")
4381
4382 if s is None:
ValueError: x and y must be the same size
我该如何解决这个问题,以便它为我绘制一个情节?
【问题讨论】:
-
你用什么参数来调用这个函数?
-
metoda_potegowa(a,x0,5) 其中 a = np.matrix([[1, 0, 3], [0, 2, 0], [3, 0, 1]]); x0 = np.matrix([1,1,1]).transpose();
标签: python python-3.x plot iteration