2) Comparisons can easily be done between components of vectors. Assume we have
ID: 3726668 • Letter: 2
Question
2) Comparisons can easily be done between components of vectors. Assume we have two vectors. X : [1 2 3], y = [6 4 2]. If we wanted to check if the first element of x is larger than the second element of y, we could write the following code: if x(1) > y(2); %This is false because x(l) is 1 and y(2) is 4 This is pretty straightforward. Similarly, if we wanted to see if the second element of x is equal to the third element of y, we could write the following: if x(2) y(3): %This is true because x(2)-2 and y(3)-2 Now what if we wanted to check multiple things? Maybe we only want to execute certain code if both the above statements are true. This is where logic operators come into play. The following code checks to see if both statements are true. If they are, then the code inside the if-block will execute. If even just one statement is false, then the codeExplanation / Answer
1.
let x = [1,2,3]
y = [4,5,6]
a.if y[3]< x[1]
......Execute some statements
b. if { (x[2] == y[2]) || (y[3] < x[3]) }
........Execute statements
c. if { [ (x[1] >y[2]) && (x[2] > y[3]) ] || (x[3]>y[1]) }
..........Execute Statements
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.