MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra

Similar documents
Linear Algebra V = T = ( 4 3 ).

Matrices Gaussian elimination Determinants. Graphics 2009/2010, period 1. Lecture 4: matrices

n n matrices The system of m linear equations in n variables x 1, x 2,..., x n can be written as a matrix equation by Ax = b, or in full

POLI270 - Linear Algebra

Review of Basic Concepts in Linear Algebra

Matrix Basic Concepts

Section 12.4 Algebra of Matrices

MATH2210 Notebook 2 Spring 2018

Review of Linear Algebra

Basic Concepts in Linear Algebra

[ Here 21 is the dot product of (3, 1, 2, 5) with (2, 3, 1, 2), and 31 is the dot product of

Linear Algebra. 1.1 Introduction to vectors 1.2 Lengths and dot products. January 28th, 2013 Math 301. Monday, January 28, 13

Basic Linear Algebra in MATLAB

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Linear Algebra /34

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Linear Algebra 1/33

Properties of Linear Transformations from R n to R m

Chapter 1: Systems of linear equations and matrices. Section 1.1: Introduction to systems of linear equations

We could express the left side as a sum of vectors and obtain the Vector Form of a Linear System: a 12 a x n. a m2

Finite Mathematics Chapter 2. where a, b, c, d, h, and k are real numbers and neither a and b nor c and d are both zero.

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

VECTORS vectors & scalars vector direction magnitude scalar only magnitude

CITS2401 Computer Analysis & Visualisation

MATRICES. a m,1 a m,n A =

1 Matrices and matrix algebra

a11 a A = : a 21 a 22

A matrix is a rectangular array of. objects arranged in rows and columns. The objects are called the entries. is called the size of the matrix, and

Chapter 2. Matrix Arithmetic. Chapter 2

A matrix is a rectangular array of. objects arranged in rows and columns. The objects are called the entries. is called the size of the matrix, and

Matrices: 2.1 Operations with Matrices

This appendix provides a very basic introduction to linear algebra concepts.

Matrix Operations. Linear Combination Vector Algebra Angle Between Vectors Projections and Reflections Equality of matrices, Augmented Matrix

CITS2401 Computer Analysis & Visualisation

is a 3 4 matrix. It has 3 rows and 4 columns. The first row is the horizontal row [ ]

Pre-Calculus I. For example, the system. x y 2 z. may be represented by the augmented matrix

Algebra & Trig. I. For example, the system. x y 2 z. may be represented by the augmented matrix

Review of linear algebra

Glossary of Linear Algebra Terms. Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB

Chapter 8: Linear Algebraic Equations

MATRICES The numbers or letters in any given matrix are called its entries or elements

Review of Coordinate Systems

Chapter 5. Linear Algebra. A linear (algebraic) equation in. unknowns, x 1, x 2,..., x n, is. an equation of the form

A = 3 B = A 1 1 matrix is the same as a number or scalar, 3 = [3].

Math Camp II. Basic Linear Algebra. Yiqing Xu. Aug 26, 2014 MIT

INSTITIÚID TEICNEOLAÍOCHTA CHEATHARLACH INSTITUTE OF TECHNOLOGY CARLOW MATRICES

A VERY BRIEF LINEAR ALGEBRA REVIEW for MAP 5485 Introduction to Mathematical Biophysics Fall 2010

2.1 Matrices. 3 5 Solve for the variables in the following matrix equation.

M. Matrices and Linear Algebra

Basic Math Review for CS4830

Dot product. The dot product is an inner product on a coordinate vector space (Definition 1, Theorem

Introduction to Matrices

Introduction. Vectors and Matrices. Vectors [1] Vectors [2]

. a m1 a mn. a 1 a 2 a = a n

Linear Algebra. The analysis of many models in the social sciences reduces to the study of systems of equations.

1. Vectors.

Vectors. The standard geometric definition of vector is as something which has direction and magnitude but not position.

A primer on matrices

CSL361 Problem set 4: Basic linear algebra

Math 360 Linear Algebra Fall Class Notes. a a a a a a. a a a

Linear Algebra Homework and Study Guide

CS 246 Review of Linear Algebra 01/17/19

Evaluating Determinants by Row Reduction

Knowledge Discovery and Data Mining 1 (VO) ( )

Elementary maths for GMT

DM559 Linear and Integer Programming. Lecture 3 Matrix Operations. Marco Chiarandini

February 20 Math 3260 sec. 56 Spring 2018

Math Linear Algebra Final Exam Review Sheet

2. Linear algebra. matrices and vectors. linear equations. range and nullspace of matrices. function of vectors, gradient and Hessian

5.1 Introduction to Matrices

We use the overhead arrow to denote a column vector, i.e., a number with a direction. For example, in three-space, we write

DM559 Linear and Integer Programming. Lecture 2 Systems of Linear Equations. Marco Chiarandini

Linear Algebra, Vectors and Matrices

ECON 186 Class Notes: Linear Algebra

MATRICES AND MATRIX OPERATIONS

7.6 The Inverse of a Square Matrix

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

Quiz ) Locate your 1 st order neighbors. 1) Simplify. Name Hometown. Name Hometown. Name Hometown.

Linear Algebra (Review) Volker Tresp 2017

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

TI89 Titanium Exercises - Part 10.

Elementary Row Operations on Matrices

Recall, we solved the system below in a previous section. Here, we learn another method. x + 4y = 14 5x + 3y = 2

2.1 Scalars and Vectors

Chapter 2 Notes, Linear Algebra 5e Lay

Linear Algebra March 16, 2019

Omm Al-Qura University Dr. Abdulsalam Ai LECTURE OUTLINE CHAPTER 3. Vectors in Physics

Matrices. 1 a a2 1 b b 2 1 c c π

Matrices. Chapter Definitions and Notations

TOPIC 2 Computer application for manipulating matrix using MATLAB

Fall Inverse of a matrix. Institute: UC San Diego. Authors: Alexander Knop

Linear Algebra (Review) Volker Tresp 2018

MATH 323 Linear Algebra Lecture 6: Matrix algebra (continued). Determinants.

LS.1 Review of Linear Algebra

Math 1B03/1ZC3 - Tutorial 2. Jan. 21st/24th, 2014

Linear Algebra. Matrices Operations. Consider, for example, a system of equations such as x + 2y z + 4w = 0, 3x 4y + 2z 6w = 0, x 3y 2z + w = 0.

+ MATRIX VARIABLES AND TWO DIMENSIONAL ARRAYS

Basic Math Review for CS1340

CSCI 239 Discrete Structures of Computer Science Lab 6 Vectors and Matrices

Cayley-Hamilton Theorem

Chapter 2. Ma 322 Fall Ma 322. Sept 23-27

Systems of Linear Equations. By: Tri Atmojo Kusmayadi and Mardiyana Mathematics Education Sebelas Maret University

Transcription:

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra A. Vectors A vector is a quantity that has both magnitude and direction, like velocity. The location of a vector is irrelevant; all that matters are magnitude and direction. You can visualize a vector as an arrow, with the length of the arrow representing the magnitude of the vector and the direction of the arrow representing the direction of the vector. A vector is usually denoted by a bold-face lower-case letter (e.g. v) or by a lower-case letter with an arrow above it (e.g. v). The magnitude (or norm) of a vector v is usually denoted either v or v. If you think of a vector as an arrow with its tail at the origin of a coordinate system, you can describe the vector analytically by specifying the location of the head of the vector. v =< 1, 2 > is the vector in the xy plane that starts at the origin and ends at the point (1, 2). A vector can have 2, 3, or more components. The magnitude of a vector is the distance from the tail to the head of the vector. < 1, 2 > = + 2 2 = 5 by the distance formula. MATLAB syntax: >> norm() Vector Operations 1. Scalar Multiplication. If k is a real number (a scalar), then k v is the vector with magnitude k v and direction the same direction as v if k > 0 and the opposite direction of v if k < 0. Analytical definition: k < v 1, v 2, v 3 >=< kv 1, kv 2, kv 3 >. 2 < 1, 2, 3 >=< 2, 4, 6 > MATLAB syntax: >> -2* 3 2. Vector Addition. Geometric definition of v + w: Place the tail of w at the head of v. The vector from the tail of v to the head of w is v + w. See the figure below. v w v+w Analytical definition of vector addition: < v 1, v 2, v 3 > + < w 1, w 2, w 3 >=< v 1 + w 1, v 2 + w 2, v 3 + w 3 >. < 1, 2, 3 > + < 4, 5, 6 >=< 5, 7, 9 > MATLAB syntax: >> 3 + 4 5 6 3. Dot Product (or Inner Product). The dot product of two vectors of the same length is a scalar. Geometric definition: v w = v w cos(θ), where θ is the angle between v and w when the vectors have their tails at the same point.

Analytical definition: v w = v 1 w 1 + v 2 w 2 + + v n w n. < 1, 2, 3 > < 4, 5, 6 >= (1)(4) + (2)(5) + (3)(6) = 32. MATLAB syntax: >> dot( 3, 4 5 6) 4. Cross Product. The cross product of two 3-component vectors v and w is a vector with magnitude v w sin (θ) and direction perpendicular to both v and w per the right-hand rule. Analytical definition: < v 1, v 2, v 3 > < w 1, w 2, w 3 >=< v 2 w 3 w 2 v 3, v 3 w 1 w 3 v 1, v 1 w 2 w 1 v 2 >. < 1, 0, 3 > < 0, 2, 1 >=< 0( 1) 2(3), 3(0) ( 1)(1), 1(2) ( 1)(0) > =< 6, 1, 2 >. MATLAB syntax: >> cross(1 0 3, 0 2-1) B. Matrices A matrix is a rectangular array of numbers. (The plural of matrix is matrices.) An m n matrix is a matrix with m rows and n columns. Here is an example of a 2 3 matrix: 3 4 5 6 If A is a matrix, then A ij denotes the element in row i and column j of matrix A. if A is the matrix defined above, then A 21 = 4. MATLAB syntax: >> 3; 4 5 6 Matrix Operations 1. Scalar Multiplication. If A is an m n matrix and k is a scalar, then ka is the m n matrix whose entries are k times the entries of A. MATLAB syntax: >> 2*A 3 4 5 6 2 2 4 6 8 10 12 2. Matrix Addition. If A and B are m n matrices, then A + B is the m n matrix with (A + B) ij = A ij + B ij. MATLAB syntax: >> A+B A + B = 1 6 3 12 3. Matrix Multiplication. If A is an m n matrix and B is an n p matrix, then AB is the m p whose ij entry equals the dot product of row i of A and column j of B. Note that for the product AB to be defined, the number of columns of A must equal the number of rows of B. AB = 1( 2) + 2( 6) 1(4) + 2(8) 3( 2) + 4( 6) 3(4) + 4(8) = 14 20 30 44

MATLAB syntax: >> A*B Note that even if A and B are both n n matrices, in general AB BA. AB = 14 20 30 44 but B 10 12 18 20 The identity matrix I n is the n n matrix with 1 along the diagonal and 0 everywhere else. 1 0 0 I 3 = 0 1 0 0 0 1 MATLAB syntax: >> eye(3) If A is an m n matrix, then I m A and AI n = A. 4. Inverse of a Matrix. For most n n matrices A there exists an inverse matrix A 1 with the property that AA 1 = A 1 I n. A 1 = (You should check this by calculating AA 1 and A 1 A.) MATLAB syntax: >> inv(a) 2 1 3/2 1/2 5. Determinant of an n n matrix. The determinant of an n n matrix A is a scalar, denoted det(a) or A. If det(a) 0, then A 1 exists and A is said to be nonsingular. If det(a) = 0, then A 1 does not exist and A is said to be singular. MATLAB syntax: >> det(a) a b c d = ad bc a b c d e f = aei + bfg + cdg gec hfa idb g h i 6. Row-echelon form of a matrix (for those of you who have studied linear algebra). The command >>rref(a) generates the reduced row echelon form of matrix A. C. Systems of Linear Equations Systems of linear equations can be expressed as matrix equations. the system x 1 + 2x 2 = 4, 3x 1 + 4x 2 = 10 can be written as the matrix equation Ax = b where x1 4, x =, and b =. 10 x 2

You can solve this system using the following MATLAB commands. >> 1, 2; 3, 4; >> b = 4; 10; >> x = A\b If the system Ax = b is overdetermined (more equations than unknowns), then A\b is a leastsquares solution of the system, i.e., a vector x that minimizes Ax b. If the system Ax = b is underdetermined (more unknowns than equations), then A\b produces a solution of the system, if there are any, or a least-squares solution if the system has no solution. D. Operations on Arrays The symbol * denotes matrix multiplication. If you want to multiply corresponding elements of arrays with the same dimensions, use.* >> 3*4 5 6 produces an error message in MATLAB, but >> 3.*4 5 6 produces the array 4 10 18. Similarly, you can perform element-by-element division or exponentiation using./ and.^ 3.^2 produces the array 1 4 9 You can apply built-in MATLAB functions to arrays, just as you can to single numbers. For example, sqrt(1 4 9) produces the array 3 E. MATLAB Array Functions Here are some useful MATLAB functions for working with arrays. MATLAB Command max(a) min(a) sum(a) mean(a) Description Largest element of A, if A is a vector Row vector containing largest element in each column, if A is a matrix Same as max(a) but gives minimum instead Sum of the elements of A if A is a vector Average of the elements of A if A is a vector

Practice Problems ( ) 1 1. The unit vector u n in the direction of vector u is given by u. Find the unit vector in u the direction of u =< 8, 14, 25 > using one MATLAB command. 2. Define the vector v = 2, 4, 6, 8, 10. Then use v to create the following vectors: 1 1 1 1 1 1 1 1 1 1 (a) a = (b) b = 2 4 6 8 10 2 2 4 2 6 2 8 2 10 2 (c) c = 5 (d) d = 1 1 1 1 1 3. Define the vectors u =< 2, 6, 5 >, v =< 5, 1, 3 >, and w =< 4, 7, 2 >. Use MATLAB s built-in functionscross anddot to verify the vector identity u ( v w) = ( u w) v ( u v) w. 4. Solve the following system of linear equations. x + 2y 3z = 5 2x y z = 0 x y + z = 1 5. (a) Generate the row array v = 1, 4, 9, 16, 25, 36, 49, 64, 81, 100. (Can you do this without typing in all 10 elements?) (b) Use a MATLAB function to find the average value of the entries of v. (c) Use a MATLAB function to find the sum of the entries of v.