Assignment 2 questions
Assignment 2 questions
2. (0.4 marks) Write a MATLAB (M-) script file that uses a for-loop and if-elseif-else structure to plot the function
x 2 + 1, x < 0
y(x=) 3 x + 1, 0 ≤ x < 10
9sin(5 x − 50) + 31, x ≥ 10
for x spanning from –5 to 15 with steps of 0.01. Use appropriate labels on your x-axis and y-axis. Show the
resulting plot. Hint: create a for-loop that steps an index i through all values of x(i) while solving for values of y(i).