用matlab写程序,希望各位援助

img

你好同学,代码供参考

% (1)
x=input('x: ');
f = @(x) 200.*(x<0) + 2*(x+100).*(x>=0&x<=50) + (6*x-x/50+1).*(x>50&x<100) + 599*(x>=100);
fprintf('y(%f)=%f\n', x, f(x));
% (2)
fplot(f, [-10,150])

输出示例

x: -1
y(-1.000000)=200.000000

x: 25
y(25.000000)=250.000000

x: 75
y(75.000000)=449.500000

x: 125
y(125.000000)=599.000000

画图

img

如有帮助还望题主给个采纳哟谢谢啦

img

img

img

img


x =input('input x:');
x1 = -10:0.1:150;
if(x<0)
    y=repmat(200,size(x1));
    ythis = 200;
else if(x>=0 &&x<=50)
        y=2*(x1+100);
        ythis=2*(x+100);
    else if(x>50 &&x<100)
        y=6*x1-x1/50+1;
        ythis=6*x-x/50+1;
        else if(x>=100)
            y=repmat(599,size(x1));
            ythis=599;
            end
        end
    end
end
 plot(x1,y);
 hold on;
 plot(x,ythis,'o');
 grid on;
 axis([-10 150 min(y)-3 max(y)+3]);