1.一元分段函数绘图例如:把下面的函数保存为Piecewise_x.m文件functionF=Piecewise_x(x)F=x.^2.*(x=0&x1)+cos(pi*(x-1)).*(x=1&x2)+(-x.^2./(x+2)).*(x=2&x=4);end运行:x=linspace(0,4);F=Piecewise_x(x);%计算相应函数值plot(x,F);%绘制曲线holdon;plot(1*ones(1,2),ylim,'r:');%画区间间隔线plot(2*ones(1,2),ylim,'r:');%画区间间隔线2.二元分段函数绘图例如:把下面的函数保存为Piecewise_xy.m文件functionPxy=Piecewise_xy(x,y)Pxy=0.5457*exp(-0.75*y^2-3.75*x^2-1.5*x).*(x+y1)+...0.7575*exp(-y^2-6*x^2).*(x+y-1)+...0.5457*exp(-0.75*y^2-3.75*x^2+1.5*x).*(x+y=-1);end运行:[x,y]=meshgrid(-3:0.1:3);s=size(x)Pxy=zeros(s(1),s(2));fori=1:s(1)forj=1:s(2)Pxy(i,j)=Piecewise_xy(x(i,j),y(i,j));endendmesh(x,y,Pxy)