clc;clear all x=-5:0.01:5; if x<=0 y=(x+sqrt(pi))./(exp(2)); else y=1/2*(log(x+sqrt(1+x.^2))); end plot(x,y);
这样的话就是数组和0比较,会只画出第二个图像
正解:
x=-5:0.01:5; y=((x+sqrt(pi))/exp(2)).*(x<=0)+((1/2)*log(x+sqrt(1+x.^2))).*(x>0); plot(x,y,'b','linewidth',2);