![图片[1]-python中怎样画分段函数?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5ecdc350c62e3490.jpg)
绘制分段函数:y=4sin(4πt)-sgn(t-0.3)-sgn(0.72-t)
importnumpyasnp importmatplotlib.pyplotasplt defsgn(x): ifx>0: return1 elifx<0: return-1 else: return0 t=np.arange(0,1,0.01) y=[] foriint: 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()
效果如下:

© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容