In: Mechanical Engineering
Suppose that x = [10, -2, 6, 5, -3] and y = [9, -3, 2, 5, -1]. Find the results of the following operations by hand and use MATLAB to check your results.
a. z = (x < 6)
b. z = (x <= y)
c. z = (x == y)
d. z = (x ~= y)
(a)
z = (x<6)
z = 0 1 0 1 1
(b)
z = (x<=y)
z = 0 0 0 1 1
(c)
z = (x==y)
z = 0 0 0 1 0
(d)
z = (x ~ =y)
z = 1 1 1 0 1
MATLAB CODE:
%Code start
clear all
x = [10 -2 6 5 -3];
y = [9 -3 2 5 -1];
z = x < 6
z = x <= y
z = x == y
z = x ~= y
%Code end
Code run result:
z = 0 1 0 1 1
z = 0 0 0 1 1
z = 0 0 0 1 0
z = 1 1 1 0 1
The results from hand and result from MATLAB are matching.
a)
z = (x<6)
z = 0 1 0 1 1
(b)
z = (x<=y)
z = 0 0 0 1 1