【发布时间】:2020-10-11 23:08:43
【问题描述】:
我正在尝试制作一个图形作为几何级数收敛的证明。这是我的代码:
import matplotlib.pyplot as graph
def cv12(nula,r,n): # nula is A0 (first term), r is common ratio and n is how many terms we want
sucet=0 # sum of series
a=nula # assign A0 as current term
konvergencia=nula/(1-r)
x=[sucet]
y=[a]
for i in range(n):
sucet=sucet+a
x.append(sucet)
print(sucet)
a=a*r
y.append(a)
graph.plot(x,y,label="Geometrický rad")
graph.plot(konvergencia,y)
cv12(1,2,5)
但我收到此错误
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 399, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (1,) and (6,)
【问题讨论】:
标签: python matplotlib plot