MATLAB: How to plot a piecewise function

functionifif statementplotplot using ifstatement

Best Answer

Solution usin if statement:
x=linspace(-5,30,1000);
for i=1:1000
if x(i)<0
y(i)=10;
elseif x(i)>=0 & x(i)<9
y(i)=10*x(i)+10;
else
y(i)=15*sqrt(4*x(i))+10;
end
end
plot(x,y)
Related Question