You are on page 1of 3
mtimes, * Matrix Multiplication Syntax c= ae example C = mtimes(A,B) Description C = A*B is the matrix product of A and B. If A is an m-by-p and B is a p-by-n matrix, then Cis an m-by-n example matrix defined by a i.) = AW, KDB. 9) im This definition says that C(i,3) is the inner product of the ith row of A with the jth column of B. You can ‘write this definition using the MATLAB® colon operator as, (4,5) = AG, +) "BC, 5) Fornonscalar A and B, the number of columns of A must equal the number of rows of 8. Matrix multiplication is notuniversally commutative for nonscalar inputs. That is, A*8 is typically not equal to a*A. at least one inputis scalar, then A*B is equivalent to A,*8 and is commutative, € = mtimes(A,B) is an alternative way to execute A*B, butis rarely used. itenables operator overloading for classes, Examples colepse a Muliply Two Vectors Create a 1-by-4 row vector, A, and a 4-by-1 column vector, 8 A= (1100); B= [15 25 35 415 Multiply A times 8, C= ASB 3 The resultis a 1-by-1 scalar, also called the dot product or inner product of the vectors A and 8, Alternatively, you can calculate the dot product A + B with the syntax dot (A,B) Multiply 8 times a, c= tA a4 2 2 33 a4 e The results a 4-by-4 matrix, also called the outer product of the vectors A and B, The outer product of two vectors, A # B, returns a matrix, Multiply Two Arrays, Create two arrays, Aand 8 A= (135; 24715 B= [-5 8 11; 3.9 21; 408]; Calculate the product of A and 8 c= Ate c 2m 35 114 3@ 52162 Calculate the inner product of the second row of A and the third column of 8 A(2,:)*B(:,3) 162 This answer is the same as C(2,3). Input Arguments colapee al AW Left Array scalar | vector | matrix Left Array, specified as a scalar, vector, or matrix. For nonscalar inputs, the number of columns in A mustbe equal to the number of rows in 8. Data Types: single | double | ints | int26 | int32 | inte4 | uints | uint46 | uint32 | uint6s | logical | char | duration | calendarburation Complex Number Support: Yes 8 — Right Array scalar | vector | matrix Right Array, specified as a scalar, vector, or matrix, For nonscalar inputs, the number of columns in A must be equal to the number of rows in 8, Data Types: single [double | int | int26 | int32 | int64 | uints | uint46 | uint32 | uint6s | logical | char | duration | calendarburation Complex Number Support: Yes Output Arguments collapse all c— Product Array scalar | vector | matrix Product Array, retumed asa scalar, vector, or matrix. Array C has the same number of rows as input A and the same umber of columns as input. For example, if is an m-by-0 empty matrix and B is a O-by-n empty matnx, then A*B is an mebyen matrix of zeros. More About + Array vs. Matrix Operations + Operator Precedence See Also colon | cross | dot | tines Introduced before R2006a

You might also like