Chapter 8. Matrices - 8 Matrices 8 .1 Setting up Matrices...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
0-8493-????-?/00/$0.00+$.50 © 2000 by CRC Press LLC © 2001 by CRC Press LLC 8 Matrices 8.1 Setting up Matrices DEFINITION A matrix is a collection of numbers arranged in a two-dimen- sional (2-D) array structure. Each element of the matrix, call it M i,j , occupies the i th row and j th column. (8.1) We say that M is an ( m n ) matrix, which means that it has m rows and n columns. If m = n , we call the matrix square. If m = 1, the matrix is a row vec- tor; and if n = 1, the matrix is a column vector. 8.1.1 Creating Matrices in MATLAB 8.1.1.1 Entering the Elements In this method, the different elements of the matrix are keyed in; for example: M=[1 3 5 7 11; 13 17 19 23 29; 31 37 41 47 53] gives M = 1 3571 1 13 17 19 23 29 31 37 41 47 53 M = MMM M M M n n mmm m n 11 12 13 1 21 22 23 2 123 L L O M L
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
© 2001 by CRC Press LLC To fnd the size oF the matrix (i.e., the number oF rows and columns), enter: size(M) gives ans = 35 To view a particular element, For example, the (2, 4) element, enter: M(2,4) gives ans = 23 To view a particular row such as the 3 rd row, enter: M(3,:) gives ans = 31 37 41 47 53 To view a particular column such as the 4 th column, enter: M(:,4) gives ans = 7 23 47 IF we wanted to construct a submatrix oF the original matrix, For example, one that includes the block From the 2 nd to 3 rd row (included) and From the 2 nd column to the 4 th column (included), enter: M(2:3,2:4)
Background image of page 2
© 2001 by CRC Press LLC gives ans = 17 19 23 37 41 47 8.1.1.2 Retrieving Special Matrices from the MATLAB Library MATLAB has some commonly used specialized matrices in its library that can be called as needed. For example: • The matrix of size ( m n ) with all elements being zero is M=zeros(m,n); For example: M=zeros(3,4) gives M = 0000 • The matrix of size ( m n ) with all elements equal to 1 is N=ones(m,n) : For example: N=ones(4,3) produces N = 111 • The matrix of size ( n n ) with only the diagonal elements equal to one, otherwise zero, is P=eye(n,n) : For example:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
© 2001 by CRC Press LLC P=eye(4,4) gives P = 1000 0100 0010 0001 • The matrix of size ( n n ) with elements randomly chosen from the interval [0, 1], such as: Q=rand(4,4) gives, in one instance: Q = • We can select to extract the upper triangular part of the Q matrix, but assign to all the lower triangle elements the value zero: upQ=triu(Q) produces upQ = or extract the lower triangular part of the Q matrix, but assign to all the upper triangle elements the value zero: loQ=tril(Q) produces loQ = 0.9708 0.4983 0.9601 0.2679 0.9901 0.2140 0.7266 0.4399 0.7889 0.6435 0.4120 0.9334 0.4387 0.3200 0.7446 0.6833 0.9708 0.4983 0.9601 0.2679 0 0.2140 0.7266 0.4399 0 0 0.4120 0.9334 0 0 0 0.6833
Background image of page 4
© 2001 by CRC Press LLC • The single quotation mark (‘) after the name of a matrix changes the matrix rows into becoming its columns, and vice versa, if the elements are all real. If the matrix has complex numbers as ele- ments, it also takes their complex conjugate in addition to the transposition. • Other specialized matrices, including the whole family of sparse matrices, are also included in the MATLAB library. You can Fnd more information about them in the help documentation.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2010 for the course ENGINEERIN ELEC121 taught by Professor Tang during the Spring '10 term at University of Liverpool.

Page1 / 56

Chapter 8. Matrices - 8 Matrices 8 .1 Setting up Matrices...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online