00:00

Understanding Matrices in Matlab: Basics and Operations

Matrices are essential in Matlab for linear algebra computations. They are two-dimensional arrays consisting of rows and columns. Learn how to create, manipulate, and perform operations on matrices using square bracket notation and common commands like transpose, identity matrix, addition, subtraction, scalar multiplication, matrix multiplication, inverse, powers, determinant, ones, and zeros. Get familiar with matrix addressing, generation, and manipulation to excel in Matlab programming.

kolesnikova
Download Presentation

Understanding Matrices in Matlab: Basics and Operations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Matrices

  2. • An m * n matrix is a two-dimensional array of numbers consisting of m rows and n columns. • Special cases are a column vector (n = 1) and a row vector • (m = 1). • Matrices are fundamental to Matlab and even if you are not intending to use Matlab for linear algebra computations you need to become familiar with matrix generation and manipulation

  3. Matrices  A Matrix array is two-dimensional, having both multiple rows and multiple columns, similar to vector arrays:  it begins with [, and end with ]  spaces or commas are used to separate elements in a row  semicolon or enter is used to separate rows. •Example: •>> f = [ 1 2 3; 4 5 6] f = 1 2 3 4 5 6 A is an m x n matrix. the main diagonal

  4. Matrices can be built explicitly using the square bracket notation. • For example, a 3-by-3 matrix comprising the rst 9 primes can be set up with the command A = [2 3 5 7 11 13 17 19 23] • The end of a row can be specified by a semicolon instead of a carriage return, so a more compact command with the same effect is “Semi-colons separate Rows” • A = [2 3 5; 7 11 13; 17 19 23] • Within a row, elements can be separated by spaces or by commas \Commas separate Columns" .

  5. Matrix Addressing -- matrixname(row, column) -- colon may be used in place of a row or column reference to select the entire row or column. Example: recall: f =  >> f(2,3) 1 2 3 4 5 6 h = 2 4 6 1 3 5 ans = 6 >> h(:,1) ans = 2 1

  6. Matrices (con’t…) more commands B = A’ eye(n)  returns an n x n identity matrix eye(m,n)  returns an m x n matrix with ones on the main diagonal and zeros elsewhere. C = A + B C = A – B B = A, where  is a scalar. C = A*B B = inv(A), A must be a square matrix in this case. rank (A)  returns the rank of the matrix A. B = A.^2  squares each element in the matrix C = A * A  computes A*A, and A must be a square matrix. det (A), and A must be a square matrix. A, B, C are matrices, and m, n,  are scalars. Transpose Identity Matrix Addition and subtraction Scalar Multiplication Matrix Multiplication Matrix Inverse Matrix Powers Determinant

  7. eye eye Identity matrix I = eye returns the scalar, 1. I = eye(n) returns an n-by-n identity matrix with ones on the main diagonal and zeros elsewhere. I = eye(4) I = 4×4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 I = eye(n,m) returns an n-by-m matrix with ones on the main diagonal and zeros elsewhere. I = eye(2,3) 1 0 0 0 1 0

  8. eye eye Identity matrix • The values of the vector in eye([2,3]) defines the size of the vector. • For example, eye([2,3]) returns a 2-by-3 array with ones on the main diagonal and zeros elsewhere. sz = [3,1]; I = eye(sz) I = 3×1 1 0 0

  9. ones ones Create array of all ones Syntax X = ones %returns the scalar 1 X = ones(n) X=ones([2*3]) % returns an n*n matrix of ones Returns 2*3 array of ones

  10. zeros zeros Create array of all zeros Syntax X = zeros %returns the scalar 0 X = zeros(n) X = zeros(sz) % returns an n*n matrix of zeros % returns an array of zeros where the size vector, sz, defines size (x) For example A = [1 4; 2 5; 3 6]; sz = size(A); X = zeros(sz) X = 3×2 0 0 0 0 0 0

More Related