12.07.2015 Views

Introduction to MATLAB 7 for Engineers - The University of Jordan

Introduction to MATLAB 7 for Engineers - The University of Jordan

Introduction to MATLAB 7 for Engineers - The University of Jordan

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Lecture 4 Computer Applications 0933201 Chapter 2We can raise a scalar <strong>to</strong> an array power.For example: if p = [2, 4, 5], then typing>>3.^p produces the array [3 2 , 3 4 , 3 5 ] = [9, 81, 243].Remember that (.^) is a single symbol. <strong>The</strong> dotin 3.^p is not a decimal point associated with thenumber 3. <strong>The</strong> following operations, with the value<strong>of</strong> p given here, are equivalent and give thecorrect answer:>> 3.^p>> 3.0.^p>> 3..^p>> (3).^p>> 3.^[2,4,5]Matrix-Matrix Multiplication (*)In the product <strong>of</strong> two matrices AB, the number <strong>of</strong>columns in A must equal the number <strong>of</strong> rows inB. <strong>The</strong> row-column multiplications <strong>for</strong>m columnvec<strong>to</strong>rs, and these column vec<strong>to</strong>rs <strong>for</strong>m the matrixresult. <strong>The</strong> product AB has the same number <strong>of</strong>rows as A and the same number <strong>of</strong> columns as B.For example:6 –210 34 79 8 (6)(9) + (– 2)(– 5) (6)(8) + (– 2)(12)–5 12 = (10)(9) + (3)(– 5) (10)(8) + (3)(12)(4)(9) + (7)(– 5) (4)(8) + (7)(12)=64 2475 1161 116(2.4–4)2-37Z.R.K37 More? See pages 92-95. Z.R.K382-38Use the opera<strong>to</strong>r ( * ) <strong>to</strong> per<strong>for</strong>m matrixmultiplication in <strong>MATLAB</strong>. <strong>The</strong> following<strong>MATLAB</strong> session shows how <strong>to</strong> per<strong>for</strong>m thematrix multiplication shown in (2.4–4).>>A = [6,-2;10,3;4,7];>>B = [9,8;-5,12];>>A*Bans =64 2475 1161 116Matrix multiplication does not have thecommutative property; that is, in general, AB BA.A simple example will demonstrate this fact:AB =whereasBA =6 –210 39 8–12 149 8–12 146 –210 3=78 2054 122134 668 65(2.4–6)(2.4–7)Reversing the order <strong>of</strong> matrix multiplication is acommon and easily made mistake!!!.=2-39Z.R.KZ.R.K392-40More? See pages 97-104.Special MatricesTwo exceptions <strong>to</strong> the noncommutative propertyare the null or zero matrix, denoted by 0 andthe identity, or unity, matrix, denoted by I.<strong>The</strong> null matrix contains all zeros and is notthe same as the empty matrix [ ], which has noelements.<strong>The</strong>se matrices have the following properties:0A = A0 = 0IA = AI = A<strong>The</strong> identity matrix is a square matrixwhose diagonal elements are all equal <strong>to</strong> one,with the remaining elements equal <strong>to</strong> zero.For example, the 4 × 4 identity matrix isI =1 0 0 00 1 0 00 0 1 00 0 0 1<strong>The</strong> functions eye(n) and eye(size(A))create an n × n identity matrix and an identitymatrix the same size as the matrix A.2-41Z.R.KZ.R.K412-42 More? See page 105.Z.R.K. 2008 Page 7 <strong>of</strong> 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!