python分段函数怎么画
绘制分段函数:
首先导入matplotlib和numpy包:
import matplotlib.plot as pltimport numpy as np
规定x范围0-100,1000个点:
x = np.linspace(0,100,1000)
设置区间:
interval0 = [1 if (i<30) else 0 for i in x]interval1 = [1 if (i>=30 and i<50) else 0 for i in x]
interval2 = [1 if (i>=50) else 0 for i in x]
列函数式:
y = np.cos(x)* interval0 + x * interval1 + np.sin(x)*interval2
绘图显示:
plt.plot(x,y)plt.show()
结果:
网,免费的在线学习python平台,欢迎关注!
以上是 python分段函数怎么画 的全部内容, 来源链接: utcz.com/z/523977.html