matlab 分段函数图象

问题描述:

matlab 分段函数图象

怎样写怎么matlab的分段函数,画出这样的图形

x1 = -4:0.1:-2*pi/3;x2 = -2*pi/3:0.1:-pi/3;x3 = -pi/3:0.1:pi/3;x4 = pi/3:0.1:2*pi/3;x5 = 2*pi/3:0.1:4;y1 = zeros(size(x1));y3 = zeros(size(x3));y5 = zeros(size(x5));y2 = 2*x2/pi+5/3;y4 = -2*x4/pi+5/3;...

为啥图形左右不对称呢??

步长0.1较大,改为比如0.01 x1 = -4:0.01:-2*pi/3;x2 = -2*pi/3:0.01:-pi/3;x3 = -pi/3:0.01:pi/3;x4 = pi/3:0.01:2*pi/3;x5 = 2*pi/3:0.01:4;y1 = zeros(size(x1));y3 = zeros(size(x3));y5 = zeros(size(x5));y2 = 2*x2/pi+5/3;y4 = -2*x4/pi+5/3;plot(x1,y1,'b',x2,y2,'b',x3,y3,'b',x4,y4,'b',x5,y5,'b')