马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
下面代码图画不出来 啥问题,谢谢"""
---------------------------------
"""
Created on Wed Mar 2 21:23:53 2022
@author: cc
"""
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0,10,int(10/0.01))
dt = 0.01
T = 10
def Boxcar(t):
if 0 <= t <= T:
Boxcar = 1
else:
Boxcar = 0
return Boxcar
def Hann(t):
if 0 <= t <= T:
Hann = 1/2(1-np.cos*(2*np.pi/T))
else:
Hann = 0
return Hann
Boxw = Boxcar(t)
Hannw = Hann(t)
plt.figure(figsize=(10,6))
plt.plot(t,Boxw,label = 'Boxcar Function')
plt.plot(t,Hannw,label = 'Hann Window')
plt.show()
你的代码有三个问题,请说一下你的具体需求:
第一:numpy数组不能用于跟 整数比较
第二:cos是函数,不能用于跟小数相乘
第三:没有2()这种用法,()是调用,整数不可调用"""
---------------------------------
"""
Created on Wed Mar 2 21:23:53 2022
@author: cc
"""
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0,10,int(10/0.01))
dt = 0.01
T = 10
def Boxcar(t):
if 0 <= t <= T: # t 不能跟整数比较
Boxcar = 1
else:
Boxcar = 0
return Boxcar
def Hann(t):
if 0 <= t <= T: # t 不能跟整数比较
Hann = 1/2(1-np.cos*(2*np.pi/T)) # cos*? 2() ?
else:
Hann = 0
return Hann
Boxw = Boxcar(t)
Hannw = Hann(t)
plt.figure(figsize=(10,6))
plt.plot(t,Boxw,label = 'Boxcar Function')
plt.plot(t,Hannw,label = 'Hann Window')
plt.show()
对你的代码修改如下:"""
Created on Wed Mar 2 21:23:53 2022
@author: cc
"""
import numpy as np
from matplotlib import pyplot as plt
t = np.linspace(0,10,int(10/0.01))
dt = 0.01
T = 10
def Boxcar(t):
Boxcar = []
for i in t:
if 0 <= i <= T:
Boxcar.append(1)
else:
Boxcar.append(0)
return Boxcar
def Hann(t):
Hann = []
for i in t:
if 0 <= i <= T:
Hann.append(1/2*(1-np.cos(2*np.pi/T)))
else:
Hann.append(0)
return Hann
Boxw = Boxcar(t)
Hannw = Hann(t)
plt.figure(figsize=(10,6))
plt.plot(t,Boxw,label = 'Boxcar Function')
plt.plot(t,Hannw,label = 'Hann Window')
plt.show()
|