用matlab画分段函数y=sin(x), 当y<0时 y=0 ; 当y>0.8时 y=0.8
00000000000000000000x=-2:0.1:2; y=0.*(x<0)+sin(x).*(x<=0.8&x>=0)+0.8*(x>0.8);
plot(x,y,'r')
0000000000000000000000000000000
例2 高数中的的取整函数y=[x] Ex-1: >> x=0:0.001:4;
>> y=0*(x<1&x>=0)+(x<2&x>=1)+2*(x<3&x>=2)+3*(x<4&x>=3);>> plot(x,y,'-r')
0000000000000000000000000000000000000000000000000000000000000
Ex-2: x=0:0.001:4;
y=0*(x<1&x>=0)+(x<2&x>=1)+2*(x<3&x>=2)+3*(x<4&x>=3);k1= find(x==1); k2= find(x==2); k3= find(x==3); k4= find(x==4);plot(x(1:k1-1),y(1:k1-1),'b', x(k1+1:k2-1),y(k1+1:k2-1),'r')hold on
plot(x(k2+1:k3-1),y(k2+1:k3-1),'c',x(k3+1:k4-1),y(k3+1:k4-1),'m')hold off
00000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000
000000000000000
例3 matlab 绘制分段函数 x>=1,y=exp(-(x-1)^2); x<1,y=x^2.其中曲线为绿虚线,并进行标注 x=-4:0.01:4;
y=(x<1).*(x.^2)+(x>=1).*(exp(-(x-1).^2)); plot(x,y,'b')
text(-2,5,'\\leftarrow y=x^2','FontSize',9) text(2,0.7,'\\leftarrow y=exp(-(x-1)^2)','FontSize',9)
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000
因篇幅问题不能全部显示,请点此查看更多更全内容