matlab分段函数编程求助 x>=0并且x<1,y=x^3+x^2+2x x>=1并且x<2,y=2x-1 x>=2,y=10 z=-(lny)/x 画出zx图 |
2013-06-18 51自学网 |
|
function fdhs1(arg1,arg2) a=arg1;b=arg2; if a==0&&b>2, x1=linspace(a+eps,1,20);y1=x1.^3+x1.^2+2*x1;[X1,Y1]=meshgrid(x1,y1);Z1=-log(Y1)./X1; x2=linspace(1,2,20);y2=2*x2+1;[X2,Y2]=meshgrid(x2,y2);Z2=-log(Y2)./X2; x3=linspace(2,b,20);y3=10*size(x3);[X3,Y3]=meshgrid(x3,y3);Z3=-log(Y3)./X3; surf(X1,Y1,Z1),xlabel('x'),ylabel('y'),zlabel('z'), text(0,120,'z=-ln(y)/x分段图'), hold on, surf(X2,Y2,Z2), surf(X3,Y3,Z3),hold off end end %上面语句保存为M文件后,在命令行输入:fdhs1(0,5) |
|
|
|