1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS 1541 -- Introduction to Computing for the Physical Sciences.

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
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 Multiplication To Multiply matrix A by matrix B: Multiply corresponding entries and then add the resulting products (1)(-1)+ (2)(3) Multiply each.
Maths for Computer Graphics
Ch 7.2: Review of Matrices For theoretical and computation reasons, we review results of matrix theory in this section and the next. A matrix A is an m.
Matrices MSU CSE 260.
Linear regression models in matrix terms. The regression function in matrix terms.
Matrices The Basics Vocabulary and basic concepts.
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.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
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.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
4.2 Operations with Matrices Scalar multiplication.
Array Math.
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,
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Lecture 28: Mathematical Insight and Engineering.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
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.
ES 240: Scientific and Engineering Computation. Chapter 8 Chapter 8: Linear Algebraic Equations and Matrices Uchechukwu Ofoegbu Temple University.
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.
Sec 4.1 Matrices.
Algebra Matrix Operations. Definition Matrix-A rectangular arrangement of numbers in rows and columns Dimensions- number of rows then columns Entries-
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
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.
ENG College of Engineering Engineering Education Innovation Center 1 Array Operations in MATLAB 1.Types of Matrix arithmetic 2.Dot operators Mathematical.
A L I MAM M OHAMMAD B IN S AUD I SLAMIC U NIVERSITY C OLLEGE OF S CIENCES D EPARTMENT OF M ATHEMATICS MATLAB 251 : MATH SOFTWARE Introduction to MATLAB.
Precalculus Section 14.1 Add and subtract matrices Often a set of data is arranged in a table form A matrix is a rectangular.
Where do you sit?. What is a matrix? How do you classify matrices? How do you identify elements of a matrix?
Matrix – is a rectangular arrangement of numbers in rows and columns. Dimensions – Size – m is rows, n is columns. m x n ( row ∙ column) Elements – The.
Matrix Algebra Definitions Operations Matrix algebra is a means of making calculations upon arrays of numbers (or data). Most data sets are matrix-type.
Array and Matrix Operations EE 201 Fall  Achieve Comprehension LOL of Array and Matrix Operations. Class Learning Objectives 2.
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.
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.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
Matrices. Matrix A matrix is an ordered rectangular array of numbers. The entry in the i th row and j th column is denoted by a ij. Ex. 4 Columns 3 Rows.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
13.4 Product of Two Matrices
Sections 2.4 and 2.5 Matrix Operations
MATRICES.
12-1 Organizing Data Using Matrices
Multiplying Matrices.
ECE 1304 Introduction to Electrical and Computer Engineering
Matrix Operations.
Matrix Operations.
Matrix Multiplication
Matrix Operations Monday, August 06, 2018.
Matrix Operations.
Section 7.4 Matrix Algebra.
WarmUp 2-3 on your calculator or on paper..
Matrices Elements, Adding and Subtracting
Introduction to MATLAB [Vectors and Matrices] Lab 2
MATRICES MATRIX OPERATIONS.
2.2 Introduction to Matrices
Objectives Multiply two matrices.
Determinant of a Matrix
3.5 Perform Basic Matrix Operations
3.6 Multiply Matrices.
Chapter 4 Matrices & Determinants
What is the dimension of the matrix below?
Introduction to Matrices
Presentation transcript:

1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences

Vectors and Matrices as Function Arguments 2 EECS Introduction to Computing for the Physical Sciences In MATLAB, an entire vector or matrix can be passed as an argument to a function such as sum, prod >> v = 1:5; >> sum(v) ans = 15 For a vector, the function will be evaluated on every element. Example: >> v = 1:5; >> prod(v) ans = 120 Means Means 1 * 2 * 3 * 4 * 5

Vectors and Matrices as Function Arguments 3 EECS Introduction to Computing for the Physical Sciences For matrices, the sum and prod functions operate on every individual column. Hence, if a matrix has dimensions: r x c, the result for the sum and prod functions will be a 1 x c row vector >> A = [1:3; 2:4; 5:7]; >> sum(A) ans = Example: from from from

Vectors and Matrices as Function Arguments 4 EECS Introduction to Computing for the Physical Sciences >> A = [1:3; 2:4; 5:7]; >> Example: How would you compute the sum of all the entries in A?

Vectors and Matrices as Function Arguments 5 EECS Introduction to Computing for the Physical Sciences Some other commonly used functions in array include: functionsdescriptionsExamples in vectors: minReturns the smallest number >> v = [ ]; >> min(v) ans = 1 maxReturns the largest number >> v = [ ]; >> max(v) ans = 4 cumsumReturns the cumulative sum >> v = [ ]; >> cumsum(v) ans = cumprodReturns the cumulative product >> v = [ ]; >> cumprod(v) ans =

Vectors and Matrices as Function Arguments 6 EECS Introduction to Computing for the Physical Sciences >> A = [1:3; 2:-1:0; 5:7]; Example: How would you determine the largest number in the following matrix?

Vectors and Matrices as Function Arguments 7 EECS Introduction to Computing for the Physical Sciences Example: >> A = [1:3; 2:4; 5:7]; >> cumsum(A) ans = Hence, the resulting matrix will have the same dimension as the input matrix. When the cumsum and cumprod functions are used in matrices, they return the cumulative sum or product of every column:

Matrix transpose 8 EECS Introduction to Computing for the Physical Sciences Example: >> A = [1 2; 3 4; 5 6] A = >> transpose_A = A’ transpose_A = If A is an m x n matrix, then the transpose of A is an n x m matrix, where the row vectors of A are written as column vectors

Scalar multiplication 9 EECS Introduction to Computing for the Physical Sciences Example of a vector: >> v = [ ]; >> v*3 ans = Numerical or arithmetic operations can be performed on every element in the entire vectors or matrices

Scalar multiplication 10 EECS Introduction to Computing for the Physical Sciences Example of a matrix: >> A = [1 3; 5 7; 2 4]; >> A*3 ans =

Scalar addition and subtraction 11 EECS Introduction to Computing for the Physical Sciences Example: >> A = [1 3; 5 7; 2 4]; >> A + 2 ans = Add every element by 2

Array operations: addition and subtraction 12 EECS Introduction to Computing for the Physical Sciences You can perform element-by-element arithmetic with two arrays of the same size >> v1 = [1 2 3]; >> v2 = [4 5 6]; >> v1 + v2 ans = Example: Adding two vectors

Array operations: addition and subtraction 13 EECS Introduction to Computing for the Physical Sciences >> A1 = [1 2 3; 2 2 5]; >> A2 = [1 0 1; 3 6 1]; >> A1 + A2 ans = Example: Adding two matrices

Array operations: addition and subtraction 14 EECS Introduction to Computing for the Physical Sciences >> A1 = [1 2 3; 2 2 5]; >> A2 = [1 0 1; 3 6 1]; >> A1 - A2 ans = Example: Subtracting two matrices

Array operations: addition and subtraction 15 EECS Introduction to Computing for the Physical Sciences >> A1 = [1 2 3; 2 2 5]; >> A2 = [1 0 1; 3 6 1]; >> A2(2,:)=[] >> A1 - A2 ans = Error using - Matrix dimensions must agree. Example: Subtracting two matrices with different dimensions

Matrix Multiplication 16 EECS Introduction to Computing for the Physical Sciences Multiplication between two matrices works as follows: To multiply a matrix A by a matrix B to result in a matrix C, the number of columns of A must equal to the number of row in B Example: 2 x 2 2 x 1 the inner dimensions must be the same

Matrix Multiplication 17 EECS Introduction to Computing for the Physical Sciences Example: >> A = [1 2; 3 2]; >> B = [4 1]’; >> A*B ans = 6 14 Multiplying two matrices

Vector Multiplication 18 EECS Introduction to Computing for the Physical Sciences To multiple 2 vectors, they must have the same number of elements, but one must be a row vector and the other a column vector OR Example: 1 x 3 3 x 11 x 1

Vector Multiplication 19 EECS Introduction to Computing for the Physical Sciences Example: >> A = [1 2 4]; >> B = [2; 0; 1]; >> A*B ans = 6 Multiplying two vectors 1 x 3 vector 3 x 1 vector

Vector Multiplication 20 EECS Introduction to Computing for the Physical Sciences Example: >> A = [1 2 4]; >> B = [2; 0; 1]; >> B*A ans = x 3 vector 3 x 1 vector Multiplying two vectors 3 x 3 matrix

Array operations: Multiplication 21 EECS Introduction to Computing for the Physical Sciences How do we perform element-by-element multiplication or division between 2 vectors or 2 matrices? Example: >> v1 = [1:6] v1 = >> v1*v1 MATLAB will interpret this one as multiplying a 1 x 6 vector with a 1 x 6 vector >> Error using * Inner matrix dimensions must agree.

Array operations: Multiplication 22 EECS Introduction to Computing for the Physical Sciences To perform element-by-element multiplication-based operation between multiple vectors, a “dot” must be placed in front of the operator operatorsdescriptionsExamples in vectors:.*element-by-element multiplication >> v = [ ]; >> v.*v ans = /element-by-element division >> v = [ ]; >> v./v ans = ^element-by-element exponentiation >> v = [ ]; >> v.^3 ans =

Array operations: Multiplication 23 EECS Introduction to Computing for the Physical Sciences Recall from LAB 2, when we plot a function that involves multiplication among sub-functions, we are performing element-by-element multiplication operation between multiple vectors Example, to plot the function: y = xe x >> x = [0:0.1:0.5] x = >> exp(x) ans = >> y = x.*exp(x) y = A row vector for the independent variable

Array operations: Multiplication 24 EECS Introduction to Computing for the Physical Sciences

Array operations: Multiplication 25 EECS Introduction to Computing for the Physical Sciences To perform element-by-element multiplication-based operation between 2 matrices, the dimensions must be the same >> A = [1 2; 3 2]; >> B = [2 0; 1 4]; >> A.*B ans = Multiply each element in the same position of A and B Final result is:

Array operations: Multiplication 26 EECS Introduction to Computing for the Physical Sciences NOTE: the difference between element-by-element multiplication and the actual matrix multiplication in this example since we have two 2 x 2 matrices >> A = [1 2; 3 2]; >> B = [2 0; 1 4]; >> A.*B ans = >> A = [1 2; 3 2]; >> B = [2 0; 1 4]; >> A*B ans = Matrix multiplication Element-by-element multiplication

Array operations: Multiplication 27 EECS Introduction to Computing for the Physical Sciences >> A = [1 2; 3 2]; >> B = [2 0; 1 4]; >> B.*A ans = >> A = [1 2; 3 2]; >> B = [2 0; 1 4]; >> B*A ans = Matrix multiplication Element-by-element multiplication A.*B = B.*A A*B ≠ B*A

Array operations: Multiplication 28 EECS Introduction to Computing for the Physical Sciences Example: >> v = [2:2:8]; >> v.^2/2 ans = Example: >> A = [ones(1,3); 1:3]; >> A.^2’ ans = ^ has higher precedence than /