Array Math.

Slides:



Advertisements
Similar presentations
Matrix.
Advertisements

Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Matrix Algebra Matrix algebra is a means of expressing large numbers of calculations made upon ordered sets of numbers. Often referred to as Linear Algebra.
3_3 An Useful Overview of Matrix Algebra
Maths for Computer Graphics
MOHAMMAD IMRAN DEPARTMENT OF APPLIED SCIENCES JAHANGIRABAD EDUCATIONAL GROUP OF INSTITUTES.
Intro to Matrices Don’t be scared….
Modified Gary Larson Far Side cartoon
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.
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.
Algebra 2: Lesson 5 Using Matrices to Organize Data and Solve Problems.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Array Math. I. Definition MATLAB is known for its mathematical power! – It does vector and MATRIX operations automatically (most languages require you.
Sundermeyer MAR 550 Spring Laboratory in Oceanography: Data and Methods MAR550, Spring 2013 Miles A. Sundermeyer Linear Algebra & Calculus Review.
MATRICES Adapted from presentation found on the internet. Thank you to the creator of the original presentation!
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.
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 5 Systems and Matrices Copyright © 2013, 2009, 2005 Pearson Education, Inc.
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
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.
4.1 Matrix Operations What you should learn: Goal1 Goal2 Add and subtract matrices, multiply a matrix by a scalar, and solve the matrix equations. Use.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Lecture 28: Mathematical Insight and Engineering.
1 C ollege A lgebra Systems and Matrices (Chapter5) 1.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
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.
Matrix Operations.
3.4 Solution by Matrices. What is a Matrix? matrix A matrix is a rectangular array of numbers.
MATRICES MATRIX OPERATIONS. About Matrices  A matrix is a rectangular arrangement of numbers in rows and columns. Rows run horizontally and columns run.
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-
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.
3.5 Perform Basic Matrix Operations Add Matrices Subtract Matrices Solve Matric equations for x and y.
Where do you sit?. What is a matrix? How do you classify matrices? How do you identify elements of a matrix?
Matrices. Matrix - a rectangular array of variables or constants in horizontal rows and vertical columns enclosed in brackets. Element - each value in.
Matrix Algebra Definitions Operations Matrix algebra is a means of making calculations upon arrays of numbers (or data). Most data sets are matrix-type.
To add, subtract, multiply, and divide, absolutely follow the mathematical rules. 1. All the rules 2. The element-per-element operator 3. Ex1: graphing.
A rectangular array of numeric or algebraic quantities subject to mathematical operations. The regular formation of elements into columns and rows.
Ch. 12 Vocabulary 1.) matrix 2.) element 3.) scalar 4.) scalar multiplication.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Matrices Introduction.
MTH108 Business Math I Lecture 20.
MAT 322: LINEAR ALGEBRA.
13.4 Product of Two Matrices
Multiplying Matrices.
Matrix Operations Free powerpoints at
Matrix Operations.
Chapter 7 Matrix Mathematics
Matrix Operations.
Matrix Operations Free powerpoints at
L6 matrix operations.
Matrix Operations Monday, August 06, 2018.
Matrix Operations.
Matrix Operations Free powerpoints at
Multiplying Matrices.
25. Basic matrix operations
Matrices.
Multiplying Matrices.
Matrix Operations Ms. Olifer.
Multiplying Matrices.
3.5 Perform Basic Matrix Operations Algebra II.
Multiplying Matrices.
Multiplying Matrices.
Presentation transcript:

Array Math

I. Definition MATLAB is known for its mathematical power! It does vector and MATRIX operations automatically (most languages require you to do this by hand). It follows the rules of ANY math book Rules of addition and subtraction are straightforward and highly common sense: think MATH Rules of multiplication and division require basic knowledge of matrix math This is an “n-by-p” matrix. n rows, p columns. Wikipedia

II. addition/subtraction (example1) Assume the vectors (actual math vectors) shown here >>v1+v2+v3 <enter> results in? v1 = 2 -3 v2 = 4 -2 v3 = -1 4 ans = 2 4 -1 -3 -2 4 ans = 5 -1 (a) (b)

II. addition/subtraction (example2) Assume the matrices A and B below. >>A+B <enter> results in? A = 2 0 -3 3 -3 4 -2 2 -1 -3 2 1 B = 8 5 7 4 6 10 9 12 10 5 11 10 ans = 10 5 4 7 3 14 7 14 9 2 13 11 ans = 2 0 -3 3 8 5 7 4 -3 4 -2 2 6 10 9 12 -1 -3 2 1 10 5 11 10 (a) (b)

II. addition/subtraction (example3) Assume the matrices A and B below. >>A+B <enter> results in? A = 2 0 -3 3 -3 4 -2 2 -1 -3 2 1 B = 8 5 7 6 10 9 10 5 11 ans = 10 5 4 3 3 14 7 2 9 2 13 1 ans = 2 0 -3 3 8 5 7 -3 4 -2 2 6 10 9 -1 -3 2 1 10 5 11 (a) (b) (c)

II. addition/subtraction (example4) Assume the matrices A and B below. >>C = B-A <enter> results in? A = 2 3 -2 5 1 2 -2 -2 B = 4 11 5 8 9 10 7 12 ans = 2 8 7 3 8 8 9 14 ??? Error using ==> minus Matrix dimensions must agree. Neither (a) nor (b) (c) (a) (b)

II. addition/subtraction (Rule #1) Addition and subtraction between arrays (vectors OR matrices) can be done if and only if BOTH dimensions match. (2 x 3) (2 x 3) By “dimensions”, understand “number of rows of A and B are equal, and number of columns of A and B are equal” This does not mean “Square” A 3by4 can be added or subtracted to a 3by4. A 100by200 can be added or subtracted to a 100by200. A 5by4 cannot be added to a 4by5. A 5by5 can be added to a 5by5.

Exception to rule #1 Adding or subtracting a scalar (a 1 by 1 array) to any array is possible. MATLAB assumes the operation is done on each element by default. A = 2 4 5 3 3 8 2 2 4 3 6 4 6 6 6 >> A+2 <enter> results in? ans = 4 6 7 5 5 10 4 4 6 5 8 6 8 8 8 2 is a 1by1 Answer: A is a 3by5 It still works!

Multiplication/Division/Power Linear Algebra has its own way of multiplying matrices. You’ll learn all about it in MA 345. MATLAB defaults to matrix multiplication.

Matrix Multiplication the Linear Algebra way Matrices can be multiplied together if and only if the inner dimensions match (2 x 3) * (3 x 3) = (2 x 3) (4 x 3) * (3 x 1) = (4 x 1) The resulting dimension is the outer dimensions. “inner dimensions”

Matrix Multiplication the Linear Algebra way A is a (2by3) matrix and B is a (3by4) matrix: True or False >>A*B <enter> is a valid statement True or False >>B*A <enter> is a valid statement >>C = A*B C will be a __ by __ matrix. >> B*A Error using * Inner matrix dimensions must agree. 2 4

Matrix Division To divide a matrix A by a matrix B really means: “To multiply matrix A by the inverse of matrix B” “inverse” does not mean “transpose”, nor “reciprocal”  All the rules of multiplications apply The inverse of a matrix is possible if and only if it is “square”: it has the same amount of rows as columns. >> A/B for example: (2by3) / (3by3) means (2by3) * inv(3by3) means (2by3) * (3by3) will work. a/b is really a*(1/b)

But I’m not in MA 345 yet… The majority of how you’ll use matrices in EGR115 will NOT be using the linear algebra method.

Multiplying/Dividing by a Scalar Multiplying together a matrix and a scalar (a 1 by 1 array) to any array is possible. MATLAB assumes the operation is done on each element per default. Note: the inner dimension obviously don’t match, so A*A wouldn’t work. A = 2 4 5 3 3 8 2 2 4 3 6 4 6 6 6 >> A*2 <enter> results in? Answer:

Multiplying/Dividing by a Scalar Dividing a matrix by a scalar (a 1 by 1 array) is possible. MATLAB assumes the operation is done on each element bydefault. CAUTION: Dividing a scalar by an array is impossible.

What if arrays don’t represent MATRICES In MATLAB, an array of multiple dimensions represents a MATRIX. Any operation (+-*/^) on these is dealt with following strict mathematical rules What if an array is simply used as a database of numbers? use the element by element operators .* ./ .^ A = 5 5 8 9 A^3 = 5 5 8 9 A^3 IS NOT 5^3 5^3 8^3 9^3 5 5 8 9 5 5 8 9 885 955 1528 1649 * * =

Assume the two following vectors: Example Calculating Prices Assume the two following vectors: One is the quantity bought of each item (1-5) The second is the price of each item (1-5) Calculate the total bill ($) So: quantities.*prices , then add all? 2 3 6 4 quantities 20.00 10.50 5.50 10.00 25.00 prices 2* 20 3* 10.5 6* 5.5 4* 10 25 + + + + = $219.50

The Dot Operator Any time you need to do math on an element-by-element basis (which will be most of the time in EGR115), you need to use the dot before the multiplication, division, and exponentiation sign. A = 5 5 8 9 A^3 = 5 5 8 9 A^3 IS NOT 5^3 5^3 8^3 9^3 5 5 8 9 5 5 8 9 885 955 1528 1649 * * = A.^3 IS 5^3 5^3 8^3 9^3

Array Functions

Basic functions on arrays CAUTION: A function will return different values depending on whether the argument is a vector or a matrix! Built-in function Argument is a vector Argument is a matrix min() Returns the minimum value of the vector Extracts the minimum of EACH column -> returns a vector max() Returns the maximum value of the vector Extracts the maximum of EACH column mean() NOT avg()!!!! AUTOMATICALLY adds all the elements in the vector together and divides by the number of elements! Extracts the average of EACH column

Basic functions on arrays Rule of thumb: If your input is a vector, it will apply the function to all the elements in the array, regardless of if the vector is a row or column vector If your input is a matrix, it will apply the function to each column and return a vector corresponding to the results from each column.

Ex. vector: Temperatures clc clear % engine temperature temps = [45.5,56.7,99.9,42,12,29]; % determine minimum,maximum,average temperature minTemp = min(temps) maxTemp = max(temps) avgTemp = mean(temps) Do not use min =, or max=…, or mean= … These keywords are reserved by MATLAB!

Ex. matrix: Scores clc clear % scores from playing. Col1 = player1, col2 = player2…etc. scores = [45,34,56; 67,3,45; 22,55,99]’; %transposed! % determine minimum,maximum,average scores minScores = min(scores) ? maxScores = ______________ avgScores = ______________