ENGR 1181 | MATLAB 5: Array Operations

advertisement
ENGR 1181 | MATLAB 5: Array Operations
Classroom Guide
Learning Objectives
1. Explain the meaning of element-by-element operations.
2. Identify situations where the standard operators in MATLAB (when used with
arrays) are reserved for linear algebra, which is not always element-by-element.
3. Apply dot operators for the cases where linear algebra is not element-by-element
and therefore dot operators are needed to produce element-by-element
calculations.
4. Apply built-in functions for analyzing arrays.
Textbook Reading
Chapter 3.4 – 3.8
Topics
This class contains the following topics:
1. Review of Scalar Math
2. Scalar-Vector Math
3. Vector-Vector Math
4. Built-in Array Functions
Outline
Below is an outline of the topics and the order in which they should be covered:
1. Review of Scalar Math
a. MATLAB has scalar math operations
b. Use MATLAB like a calculator for basic mathematical operations: addition,
subtraction, multiplication, division, etc.
2. Scalar-Vector Math (Classroom Activity – Example 1, Example 2)
a. Show examples of scalar-vector addition/subtraction
i. MATLAB computes element-by-element as default
ii. No “dot” operator needed
b. Show examples of scalar-vector multiplication/division
i. MATLAB computes element-by-element as default for multiplication
ii. No “dot” operator needed for scalar-vector multiplication
iii. Division works without a “dot” operator ONLY when the scalar is to
the right of the division sign.
1
ENGR 1181 | MATLAB 5: Array Operations
Classroom Guide
3. Vector-Vector Math (Classroom Activity – Examples 3, 4 & 5)
a. Show examples of vector-vector addition/subtraction
i. No “dot” operator needed. Default is element-by-element
ii. Vectors used in computation must be of the same length.
b. Show examples of vector-vector multiplication/division
i. Without the “dot” operator, MATLAB solves calculations with arrays
following the rules of linear algebra. We won’t be doing linear
algebra in this class so we need to run element-by-element
computations.
ii. When multiplying or dividing two arrays, include the “dot” operator
BEFORE the mathematical symbol.
c. Show examples of exponential calculations
i. Exponents are not actually scalar operations. They are operations
involving the product of the same vector.
ii. Include the “dot” operator BEFORE the mathematical symbol. This is
true when raising a vector to a scalar or to another vector.
4. Built-in Array Functions (Classroom Activity – Example 6)
a. MATLAB has many built-in functions for analyzing arrays and matrices. For
example:
i. mean()
ii. sum()
iii. sort()
iv. median()
v. std()
vi. max()
5. Prompt: Remember what is DR PIE?
6. Students will complete Part 1 of the assignment to turn in by the end of class.
Once finished, students may start on Part 2 due by the next class. Students will
submit Part 1 of the assignment to the Carmen dropbox as a PDF.
2
Download