To add, subtract, multiply, and divide, absolutely follow the mathematical rules. 1. All the rules 2. The element-per-element operator 3. Ex1: graphing.

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Maths for Computer Graphics
Section 4.1 – Matrix Operations Day 1
Intro to Matrices Don’t be scared….
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
1 Chapter 3 Matrix Algebra with MATLAB Basic matrix definitions and operations were covered in Chapter 2. We will now consider how these operations are.
4.2 Adding and Subtracting Matrices 4.3 Matrix Multiplication
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
4.2 Operations with Matrices Scalar multiplication.
Algebra 2: Lesson 5 Using Matrices to Organize Data and Solve Problems.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
Array Math.
THU, JAN 8, 2015 Create a “Big Book of Matrices” flip book using 4 pages. Do not make your tabs big! BIG BOOK OF MATRICES What is a Matrix? Adding & Subtracting.
Matrix Entry or element Rows, columns Dimensions Matrix Addition/Subtraction Scalar Multiplication.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Chapter 4 Matrices By: Matt Raimondi.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Matrices Addition & Subtraction Scalar Multiplication & Multiplication Determinants Inverses Solving Systems – 2x2 & 3x3 Cramer’s Rule.
Lecture 28: Mathematical Insight and Engineering.
Unit 3: Matrices.
Matrix Arithmetic. A matrix M is an array of cell entries (m row,column ) and it must have rectangular dimensions (Rows x Columns). Example: 3x x.
13.1 Matrices and Their Sums
Lesson 11-1 Matrix Basics and Augmented Matrices Objective: To learn to solve systems of linear equation using matrices.
Class Opener:. Identifying Matrices Student Check:
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Matrix Algebra Section 7.2. Review of order of matrices 2 rows, 3 columns Order is determined by: (# of rows) x (# of columns)
Array Operations ENGR 1181 MATLAB 4.
Algebra 1 Chapter 2 Section : Solving One-Step Equations An equation is a mathematical statement that two expressions are equal. A solution of an.
Sec 4.1 Matrices.
MT411 Robotic Engineering Asian Institution of Technology (AIT) Chapter 1 Introduction to Matrix Narong Aphiratsakun, D.Eng.
Algebra Matrix Operations. Definition Matrix-A rectangular arrangement of numbers in rows and columns Dimensions- number of rows then columns Entries-
Chapter 1 Section 1.5 Matrix Operations. Matrices A matrix (despite the glamour of the movie) is a collection of numbers arranged in a rectangle or an.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
MATRIX A set of numbers arranged in rows and columns enclosed in round or square brackets is called a matrix. The order of a matrix gives the number of.
Section – Operations with Matrices No Calculator By the end of this lesson you should be able to: Write a matrix and identify its order Determine.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
3.5 Perform Basic Matrix Operations Add Matrices Subtract Matrices Solve Matric equations for x and y.
Essential Question: Why, oh why, didn’t I take the blue pill?
(4-2) Adding and Subtracting Matrices Objectives: To Add and subtract Matrices To solve certain Matrix equations.
Unit 3: Matrices. Matrix: A rectangular arrangement of data into rows and columns, identified by capital letters. Matrix Dimensions: Number of rows, m,
Systems of Equations and Matrices Review of Matrix Properties Mitchell.
Where do you sit?. What is a matrix? How do you classify matrices? How do you identify elements of a matrix?
2.3 MODELING REAL WORLD DATA WITH MATRICES By the end of the section students will be able to add, subtract, and multiply matrices of various sizes. Students.
MTH108 Business Math I Lecture 20.
Alg 2 Ch 6 Matrices.
13.4 Product of Two Matrices
Multiplying Matrices.
Matrices Rules & Operations.
Warm-Up - 8/30/2010 Simplify. 1.) 2.) 3.) 4.) 5.)
Matrix Operations Monday, August 06, 2018.
Matrix Operations Add and Subtract Matrices Multiply Matrices
Matrix Operations SpringSemester 2017.
Multiplying Matrices.
WarmUp 2-3 on your calculator or on paper..
Matrices Elements, Adding and Subtracting
Unit 3: Matrices
Multiplying Matrices.
3.6 Multiply Matrices.
1.8 Matrices.
What is the dimension of the matrix below?
Matrix Operations SpringSemester 2017.
1.8 Matrices.
Multiplying Matrices.
Multiplying Matrices.
Multiplying Matrices.
Presentation transcript:

To add, subtract, multiply, and divide, absolutely follow the mathematical rules. 1. All the rules 2. The element-per-element operator 3. Ex1: graphing 4. Ex2: calculating a bill Arithmetic Ops’ on Arrays 11

Every Operation is Different! 2 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ ???? ???? ???? ???? ???? ???? “Safe” or “Caution”?

Scalar  Scalar +-*/ All operations (+ - * / ) are valid, no exceptions. >> A=2; >> B=-3; A goes first B goes first 3

Every Operation is Different! 4 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ ???? ???? ???? ???? ????

Scalar  Vector + All safe! >> n = 2; >> vr = [1 2 3]; %row vector >> vc = [-1; -2; -3]; %colum vector Results are identical. 5

Scalar  Vector - All safe! >> n = 2; >> vr = [1 2 3]; %row vector >> vc = [-1; -2; -3]; %colum vector Results are opposite when flipped. 6

Scalar  Vector * All safe! >> n = 2; >> vr = [1 2 3]; %row vector >> vc = [-1; -2; -3]; %colum vector Identical results when flipped 7

Scalar  Vector / CAUTION! >> n = 2; >> vr = [1 2 3]; %row vector >> vc = [-1; -2; -3]; %colum vector All good when vector goes first 8

Scalar  Vector / CAUTION! >> n = 2; >> vr = [1 2 3]; %row vector >> vc = [-1; -2; -3]; %colum vector Strange result when scalar goes first! 9 2 [1 2 3] “Multiplies by the inverse vector”… Dividing by a row goes against the rules in math.

Scalar  Vector./ Now, when the intention is to execute the division on EACH element of the array, a new operator exists: The element-per-element operator:./ “dot-divide” 10 2/-1 2/-2 2/

Every Operation is Different! 11 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ ???? ???? ???? ????

Scalar  Matrix +-* Assume a scalar and a 2 by 4 matrix >> n = 2; >> mat = [ ; ]; Addition, subtraction, and multiplication are fine, regardless of who goes first. Below are addition and multiplication examples only: 12 Can you guess who has issues…

Scalar  Matrix /./ Dividing by a scalar is fine! Each element is divided by Dividing of course…

Scalar  Matrix /./ Dividing by a scalar is fine! Each element is divided by 2. Once again, to divide a scalar by a matrix is invalid. Use the “dot-divide” to divide the scalar by EACH element. 14 Again, this is due to rules in mathematics Dividing of course…

Every Operation is Different! 15 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ ???? ???? ????

Every Operation is Different! 16 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ ???? ???? ???? “Safe” or “Caution”?

Vectors, Matrices +- The rule is the same, whether applied to vectors or matrices. “Given variables that are not scalars, they can be added or subtracted (in any directions) if and only if their dimensions are identical!” Matlab simply adds (or subtracts) the elements placed in the same location (row, col). Therefore, each element must have its ‘brother/sister’ in the other variable! 17 + ???

Vectors, Matrices +- Vectors Matrices + - Note: Subtracting the opposite way gives the opposite result. Both matrices are 2 by 3’s. Both vectors are 1 by 3’s.

Ex1: Adding Vectors 19 Source: hyperphysics.phy-astr.gsu.edu/hbase/vect.htmlhyperphysics.phy-astr.gsu.edu/hbase/vect.html ? ? Advantage of arrays? 3 variables instead of 6 (one for each value)!!!

Ex1: Adding Vectors There is no limit to the amount/directions of vectors. The dimensions of each vector must match: here [x, y] 20 Source: hyperphysics.phy-astr.gsu.edu/hbase/vect.htmlhyperphysics.phy-astr.gsu.edu/hbase/vect.html

Every Operation is Different! 21 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ ?? ?? ?? As long as the dimensions are exactly the same.

Every Operation is Different! 22 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ ?? ?? ?? As long as the dimensions are exactly the same.

Vectors, Matrices * / It is possible to multiple and divide arrays together, as long as the “MATRIX-EXPRESSION” is valid. not, Not, NOT as long as the dimensions match! Remember: MATLAB = “Matrix Laboratory” Multiplying vectors/matrices with the * operator alone does NOT multiply each element by its brother/sister in the same location. Same for divide, it does NOT mean element-by- element. 23 So.. What does it do…

Multiplication only * For example It is mathematically doing what it is supposed to do: “Matrix Multiplication”. What must be understood: the * operator alone is NOT meant to multiply element-by-element by 22 by 2 6*1+3*2 6*3+3*2 9*1-5*2 9*3-5*2 4*1+2*2 4*3+2*2 3 by 2 *

Multiplication only, cont. To multiply matrices and/or vectors using the * operator alone, the “inner-dimensions must match”. Visually, this means: 25 * R1 by C1 R2 by C2 C1 must be equal to R2

Multiplication only, cont. To multiply matrices and/or vectors using the * operator alone, the “inner-dimensions must match”. Visually, this means: 26 * R1 by C1 R2 by C2 C1 must be equal to R R1 by C2 Ironically, the resulting matrix has R1 rows and C2 columns (the exterior dimensions..)!

Multiplication only, cont. 2 more examples: The “Inner-Dimensions must match” by 1 1 by 2 6*1 6*3 9*1 9*3 4*1 4*3 -1*1-1*3 * by 1 2 by 2 * by 2

Multiply element-per-element If the intention is NOT TO MATRIX-MULTIPLY, but to regard the array as a collection of data and apply EQUATIONS TO EACH ELEMENT, use the element- per-element operator.* “dot-multiply”. This is best shown in examples. 28

Ex1. Plotting graphs Recall an example from the chapter “Creating Arrays” x = linspace(-10,10,20); %array of 20 data points y = x.*x; %calculate array of y’s %(The dot will be explained next time…) plot(x,y) %plot command Statements that would create errors: y = x*x; y = x^2; Matlab would try to do vector-multiplication! Statement that would work as well: y = x.^ 2; %the “dot-caret” operator 29

Ex2. Calculating 30

Division only / Using the / operator alone between vectors/matrices tells Matlab to “multiply by the inverse”. If it is the intention of the programmer, all is good! Note: if you have not learned what “multiply by the inverse” mean, no panic as we will not ask you to explicitly apply this. However, you must be able to just state what / does. 31

Division only, cont. If the intention, however, is to divide each element of a vector by the elements of another (same for matrices), use the element-per-element operator./ “dot-divide”! The (r by c) dimensions must exactly match for both variables Example for vectors: 32

Division only, cont. Example for matrices: A and B are both 2by3’s (2rows by 3 columns). Note how A/B gives back a 2by2, not a 2by3. 33

Use the operators wisely! 1. Are you doing math? 2. Are you doing element-per- element operations? Wrapping Up Rules are: The element-per-element operators are:.* and./ 34 Scalar Vector Matrix Vector Scalar Vector Matrix Scalar Vector Matrix +-*/ As long as the dimensions are exactly the same.