Create an entire array and using for loops. Define a vector x over the range of -10 to 10 with a resolution of 1000 points. Then, please write requested MATLAB scripts to plot the piecewise function (note: plot(x,y) is sufficient, DO NOT USE fplot):
y=?, ? < −5
? = −3, −5 ≤ ? ≤ 0
y=?^2, 0<?<5
y=7, ?≥5
Use nested if statements (with a for loop)
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
clc
clear all
close all
format long
x=linspace(-10,10,1000);
y=[];
for i=1:length(x)
if(x(i)<-5)
y(i)=x(i);
end
if(x(i)>=-5&&x(i)<=0)
y(i)=-3;
end
if(x(i)>0&&x(i)<5)
y(i)=x(i)^2;
end
if(x(i)>=5)
y(i)=7;
end
end
plot(x,y);
Kindly revert for any queries
Thanks.
Get Answers For Free
Most questions answered within 1 hours.