Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用numpy和matplotlib绘制sympy函数_Numpy_Matplotlib_Jupyter Notebook_Sympy - Fatal编程技术网

使用numpy和matplotlib绘制sympy函数

使用numpy和matplotlib绘制sympy函数,numpy,matplotlib,jupyter-notebook,sympy,Numpy,Matplotlib,Jupyter Notebook,Sympy,以下是我想做的: # the standard broiler plate for jupyter %matplotlib inline from matplotlib.pyplot import * from sympy import * import numpy as np init_printing() t = symbols('t') x1 = 2*cos(3*pi*t + pi/4) x2 = x1.diff(t) display(x1) display(x2) pi2 = 2*

以下是我想做的:

# the standard broiler plate for jupyter
%matplotlib inline
from matplotlib.pyplot import *
from sympy import *
import numpy as np
init_printing()

t = symbols('t')

x1 = 2*cos(3*pi*t + pi/4)
x2 = x1.diff(t)
display(x1)
display(x2)

pi2 = 2*np.pi
vt  = np.arange(0, pi2, 0.1)
vx1 = np.zeros(len(tv))
vx2 = np.zeros(len(tv))

for n in range(0,len(vt)):
    vx1[n] = N(x1.subs(t,vt[n]))
    vx2[n] = N(x2.subs(t,vt[n]))

title('Signal')
plot(vt, vx1)
show()

title('Derivative of signal')
plot(vt, vx2)
show()
上面这句话似乎应该管用。。。但是,我收到了意外的错误消息:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-41-eaccf9c2bc6b> in <module>()
     14 
     15 title('Signal')
---> 16 plot(vt, vx1)
     17 show()
     18 title('Instantanious Frequency')

C:\Python35\lib\site-packages\sympy\plotting\plot.py in plot(*args, **kwargs)
   1289     series = []
   1290     plot_expr = check_arguments(args, 1, 1)
-> 1291     series = [LineOver1DRangeSeries(*arg, **kwargs) for arg in plot_expr]
   1292 
   1293     plots = Plot(*series, **kwargs)

TypeError: 'NoneType' object is not iterable
matplotlib.pyplot有一个plot方法,sympy也有,当您导入*时,它会变得有点混乱

%matplotlib inline
import matplotlib.pyplot as plt
import sympy
import numpy as np
sympy.init_printing()

t = sympy.symbols('t')

x1 = 2 * sympy.cos(3 * sympy.pi * t + sympy.pi / 4)
x2 = x1.diff(t)
display(x1)
display(x2)

pi2 = 2 * np.pi
vt  = np.arange(0, pi2, 0.1)
vx1 = np.zeros(len(vt))
vx2 = np.zeros(len(vt))

for n in range(0,len(vt)):
    vx1[n] = sympy.N(x1.subs(t, vt[n]))
    vx2[n] = sympy.N(x2.subs(t,vt[n]))

plt.title('Signal')
plt.plot(vt, vx1)
plt.show()

plt.title('Derivative of signal')
plt.plot(vt, vx2)
plt.show()

你改变了什么?这只是名称空间冲突吗?@BillMoore将matplotlib.pyplot导入为plt并导入sympy@BillMoore一个更简单的解决方案是首先导入Symphy,但我认为这只会掩盖实际问题。我的建议是避免使用foo进口*