绘制分段函数:y=4sin(4πt)-sgn(t-0.3)-sgn(0.72-t)

成都创新互联专注于香河企业网站建设,成都响应式网站建设,商城系统网站开发。香河网站建设公司,为香河等地区提供建站服务。全流程按需定制开发,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务
import numpy as np
import matplotlib.pyplot as plt
def sgn(x):
if x > 0:
return 1
elif x < 0:
return -1
else:
return 0
t = np.arange(0, 1, 0.01)
y = []
for i in t:
y_1 = 4 * np.sin(4 * np.pi * i) - sgn(i - 0.3) - sgn(0.72 - i)
y.append(y_1)
plt.plot(t, y)
plt.xlabel("t")
plt.ylabel("y")
plt.title("Heavsine")
plt.show()
效果如下:
当前题目:创新互联Python教程:python中怎样画分段函数?
转载来于:https://chengdu.cdxwcx.cn/article/cdpcdce.html