Computation for the Sciences: Lab 3 :: Precedence, Color and Plotting
Precedence
Here are MATLAB's rules*:
*The table below is adapted from
Mastering MATLAB 7
by Hanselman and Littlefield.
Operator Precedence (from highest to lowest)
- Parentheses ()
- Transpose (.'), conjugate transpose ('), power (.^), matrix power(^)
- Unary plus (+), unary minus (-), negation (~)
- Multiplication (.*), matrix multiplication (*), right division (. /), left division (.\), matrix right division (/), matrix left division (\)
- Addition (+), subtraction (-), logical negation (~)
- Colon operator (:)
- Less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), not equal to (~=)
- Element-wise logical AND (&)
- Element-wise logical OR (|)
Reminders:
- Operators of the same precedence are evaluated from left to right
- Precedence can be overridden with parentheses
- Please Excuse My Dear Aunt Sally
I. Practice with Precedence
Evaluate these expressions (by hand!):
- 2 ^ 2 * 4
- 5 + 4 - 3 ^ 2 * 1
- (3 > 4) | (2 < 10) == 1
- alex = (10 == (8 - 6 ) * 5)
- 1 : 4 * 2
- sox = 1 < 1
- sox = 0 < 0.5 < 1
- sox = 2 == 2
II. Using color in plot
Let's extend beyond the 8 built-in MATLAB colors here.
III. Multiple plots in one figure
An example of using subplot.
Prelude to Assignment 2
Assignment 2 contains three Exercises and one extended programming problem.
The Exercises are: 1) practice with conditional expressions, 2) Red Sox statistics
and 3) indexing with colon notation.
Click here for the Exercises.
Uploading your saved work
Use Fetch to upload your saved work.
Work-in-progress should go into your personal cs112/
folder.