RA Ch 6 Part 1
docx
keyboard_arrow_up
School
Lone Star College System, Woodlands *
*We aren’t endorsed by this school
Course
1302
Subject
Mathematics
Date
Apr 3, 2024
Type
docx
Pages
3
Uploaded by ConstableBuffalo405
EGR 1302
RA – Ch 6 (5
th
Ed.)
Chapter 6 Reading Assignment – Part 1
Instructions
Read Chapter 6 of MATLAB – An Introduction with Applications
by Gilat, and find the answers to
the following questions. Write down the answers to each question on this handout.
Section 6.1
1.
What is the difference between a relational operator and a logical operator?
2.
What is the difference between “=” and “==”?
3.
What is the result when two arrays are compared using a relational operator?
4.
Review the first gray-highlighted section of example code. Why is the first value of the “d” vector zero?
5.
Notice: The book has an incorrect statement in the first bullet after the gray-highlighted section containing variables “r” through “w”. Numerical arrays CAN be used to address other arrays, but they behave differently than a logical (or Boolean) array. Example:
>> x = [5 12 -4 6]; y = [1 12 -4 6];
>> z = (x == y)
z =
1×4 logical array
0 1 1 1
>> x(z) ans =
12 -4 6
>> q = [1 4];
>> x(q) ans =
5 6
1
z is a logical or “Boolean” array of 0’s and 1’s. The 1’s appear where the comparison “x==y” is true.
Using z to index (or address) the vector x, the result is the values of x where z is 1. In this case, the last three.
q is a numerical array. Using q to index the vector x, the result is the values of x at the locations specified by
the numbers of q. In this case, locations 1 and 4.
EGR 1302
RA – Ch 6 (5
th
Ed.)
6.
Looking at the example code in the same gray-highlighted section as in (5) above, why does the “t” vector contain the four values [8 9 4 10]?
7.
What is the order of precedence for arithmetic, relational, and logical operators when they are combined in mathematical expressions?
1 (highest) ________________________
2 ________________________
3
________________________
4
________________________
5
________________________
6
________________________
7
________________________
8 (lowest)
________________________
8.
Fill in the truth table for the following logical operations:
Input
Output
A
B
A&B
A|B
xor(A,B)
~A
~B
0
5
4
-3
[0 0 1 1]
[0 1 0 1]
[-5 7 0]
[13 1 4]
2
EGR 1302
RA – Ch 6 (5
th
Ed.)
Section 6.2
9.
Why are the commands between the if
statement and the end
statement automatically indented?
10. What is the difference between the if-end
structure, the if-else-end
structure and the if-
elseif-else-end
structure?
Section 6.3
11. What happens if a match is found in a switch-case
statement?
12. What happens if no match is found in a switch-case
statement?
13. What is the purpose of the otherwise
case?
3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help