MATLAB 绘制分段二次函数的问题,出来只有一个点,谁能帮我修改下?for x=-5:1:5;if x>=0fprintf('x=%d',x)F=x.^3+5;plot(x,F,'.b')elsefprintf('x=%d',x)F=-x.^3+5;plot(x,F,'.b')endend

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 22:40:06
MATLAB 绘制分段二次函数的问题,出来只有一个点,谁能帮我修改下?for x=-5:1:5;if x>=0fprintf('x=%d',x)F=x.^3+5;plot(x,F,'.b')elsefprintf('x=%d',x)F=-x.^3+5;plot(x,F,'.b')endend

MATLAB 绘制分段二次函数的问题,出来只有一个点,谁能帮我修改下?for x=-5:1:5;if x>=0fprintf('x=%d',x)F=x.^3+5;plot(x,F,'.b')elsefprintf('x=%d',x)F=-x.^3+5;plot(x,F,'.b')endend
MATLAB 绘制分段二次函数的问题,出来只有一个点,谁能帮我修改下?
for x=-5:1:5;
if x>=0
fprintf('x=%d',x)
F=x.^3+5;
plot(x,F,'.b')
else
fprintf('x=%d',x)
F=-x.^3+5;
plot(x,F,'.b')
end
end

MATLAB 绘制分段二次函数的问题,出来只有一个点,谁能帮我修改下?for x=-5:1:5;if x>=0fprintf('x=%d',x)F=x.^3+5;plot(x,F,'.b')elsefprintf('x=%d',x)F=-x.^3+5;plot(x,F,'.b')endend
你在每一个绘图之后添加一个 hold on
就行了

for x=-5:0.1:5;
if x>=0
fprintf('x=%d',x)
F=x.^3+5;
plot(x,F,'.b')
hold all
else
fprintf('x=%d',x)
F=-x.^3+5;
plot(x,F,'.b')
hold all
end
end

x=-5:1:5;
if x>=0
fprintf('x=%d',x);
f_x=x.^3+5;
else
fprintf('x=%d',x);
f_x=-x.^3+5;
end
F=(x.^3+5).*(x>=0)+(-x.^3+5).*(x<0);
plot(x,F);