t=-1000:0.1:1000;
f=t.*(-1000
x=x1+0.5;
y=x.*(-1
按上面语句试试
x=-1:0.1:4.5;
plot(x,fu(x))
函数文件:
function y=fu(x)
y=x;
for i=1:length(x)
if (x(i)>=1) & (x(i)<=4)
y(i)=x(i)^2;
elseif x>4
y(i)=2^x(i);
end
end
x=-0.5:0.01:5;
for i=1:length(x);%%%以下为分段函数
if x(i)<1
F(i)=x(i);
elseif x(i)<=4
F(i)=x(i)^2;
else
F(i)=2^x(i)
end
end
plot(x,F)%%绘图语句