Question

Create an entire array and using for loops. Define a vector x over the range of...

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

  1. Use nested if statements (with a for loop)

Homework Answers

Answer #1

`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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create an entire array and using for loops. Define a vector x over the range of...
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 logical indexing (do not use loops)
1. Now generate y array using the function file my_func for the x array varying from...
1. Now generate y array using the function file my_func for the x array varying from 0 to 4 with an increment of 0.2. Generate x and y arrays without using any loop statement and do not print these arrays. 2. Off of question 1. Using MATLAB plot routine, plot y-array against the x-array generated in question 1. On this plot show grid lines, label the axes as x and y, and write the text ‘y=f(x)’ next to the plotted...
Let x be the vector 1:366. Use a nested for loop to estimate, for each value...
Let x be the vector 1:366. Use a nested for loop to estimate, for each value of the vector x[i] = i, the corresponding probability y[i] that there will be at least one common birthday if there are i people in a room (ignore leap years, as usual). Your for loop should create a vector y of the same size as x. Now use the plot command plot(x,y) to draw the graph. Use google to see how to add some...
Using MATLAB The range of an object shot at an angle θ (with respect to x-axis),...
Using MATLAB The range of an object shot at an angle θ (with respect to x-axis), with the initial velocity of V0 (in the absence of air resistance), is calculated by the following formula: range=(Vo^2/g)(sin(2theta)) where (0<=theta<=pi/2) And the trajectory of object is given by:     h=tan(theta).x-(g/2Vo^2*cos^2(theta)).x^2 .Where h is the height of the object at each x location and g = 9.81 m/s2. a) Using π/8 increment size for the angle and V0 = 10 m/s, plot the trajectories of...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
Q) a) create a matrix named as X of evenly spaced values from 0 to 50,...
Q) a) create a matrix named as X of evenly spaced values from 0 to 50, with an increment of 10. b) a) create a matrix named as Y of evenly spaced values from 500 to 1000, with an increment of 3. c)a) create a matrix named as Z, the value of the 1st row is from 1 to 10, 2nd row from 2 to 20 with increment of 2, 3rd row 3 to 12. using subplot divide the window...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
14. Practice questions a. Create an anonymous function called func1 for the dummy argument x that...
14. Practice questions a. Create an anonymous function called func1 for the dummy argument x that finds the exponential of the negative one-half times the argument, and multiplies it by the sine of five times the argument. If given a vector or matrix, the function should perform element-by-element processing. b. Using plot(), plot plotr -vs- func1(plotr) as a blue line. Then plot this same function again over the same range (0, 5) as a dashed red line using fplot(), keeping...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT