用matlab绘制分段函数曲线

代码:

x=linspace(-5,5,100);
y=[];
for x0=x;
if x0>0
    y=[y,1/2*log(x0+sqrt(1+x0.^2))];
else
    y=[y,(x0+sqrt(pi))/exp(2)];
end
end
plot(x,y)
结果:

猜你喜欢

转载自blog.csdn.net/weixin_41983807/article/details/83006244