Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that MATLAB vectors x and y are defined as follows: x = [-2.5, 4, 9, 0,

ID: 3589871 • Letter: S

Question

Suppose that MATLAB vectors x and y are defined as follows: x = [-2.5, 4, 9, 0, -1, 0.1]; y = -0.2:0.3:1.5; Determine the values of each of the following expressions, without evaluating them with MATLAB, and then confirm your results with MATLAB. If your result disagrees with the MATLAB result, explain why your answer was incorrect. If an expression is invalid, indicate this as your result. Turn in your written results as well as a copy of your command window for the following expressions. a. x(4) b. y(3) c. x(3) + y(6) d. x – 4 e. 2*y + 3*x f. x + y(5) g. size(y) h. x(length(x)) i. x(3:end) j. y(x(2)) k. x(y(2))

Explanation / Answer

PLEASE REFER BELOW MATLAB CODE

clear all
clc

x = [-2.5 4 9 0 -1 0.1]

y = -0.2:0.3:1.5

%a)
x_4 = x(4)

%b)
y_3 = y(3)

%c)
x_3_add_y_6 = x(3) + y(6)

%d)
x_sub_4 = x - 4

%e)
y_2_add_3_x = 2 .* y + 3 .* x

%f)
x_add_y_5 = x + y(5)

%g)
size_y = size(y)

%h)
x_length_x = x(length(x))

%i)
x_3_end = x(3:end)

%j)
y_x_2 = y(x(2))

%k)
x_y_2 = x(y(2))

PLEASE REFER BELOW OUTPUT


x =

-2.5000 4.0000 9.0000 0 -1.0000 0.1000


y =

-0.2000 0.1000 0.4000 0.7000 1.0000 1.3000


x_4 =

0


y_3 =

0.4000


x_3_add_y_6 =

10.3000


x_sub_4 =

-6.5000 0 5.0000 -4.0000 -5.0000 -3.9000


y_2_add_3_x =

-7.9000 12.2000 27.8000 1.4000 -1.0000 2.9000


x_add_y_5 =

-1.5000 5.0000 10.0000 1.0000 0 1.1000


size_y =

1 6


x_length_x =

0.1000


x_3_end =

9.0000 0 -1.0000 0.1000


y_x_2 =

0.7000

Subscript indices must either be real positive integers or
logicals.

Error in vector_eval (line 39)
x_y_2 = x(y(2))

>>

HERE PROBLEM NUMBER (k) IS INVALID BECAUSE

y(2) = 0.1 (matlab array index starts from 1)

x(y(2)) = x(0.1) which is not possible as array index should be real positive intergers and hence it's not possible

all other (a) ..... (j) is possible and evaluated by using MATLAB.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote