Description
Given a matrix A, output the matrix multiply by its transpose matrix.
The transpose matrix of a matrix is created by the following rules:
1. If matrix A is n by m, the transpose matrix of A is m by n.
2. Put the rows of A as the columns of transpose matrix.
or put the columns of A as the rows of transpose matrix.
Formally, the i th row, j th column element of AT, is the j th row, i th column element of A:
For example, if the matrix A is:
the transpose matrix of A is:
About matrix multiplication:
For matrix A(n by m) and matrix B(m by p),
the matrix product AB (denoted without multiplication signs or dots) is defined to be the n × p matrix
where each i, j entry is given by multiplying the entries Aik (across row i of A) by the entries Bkj (down column j of B), for k = 1, 2, ..., m, and summing the results over k:
(From wikpedia: Matrix multiplication)
Take our sample input for example:
Out11 = A11*AT11 + A12*AT21 = 1*1 + 4*4 = 17
Out12 = A11*AT12 + A12*AT22 = 1*2 + 4*5 = 22
Out13 = A11*AT13 + A12*AT23 = 1*3 + 4*6 = 27
Out21 = A21*AT11 + A22*AT21 = 2*1 + 5*4 = 22
Out22 = A21*AT12 + A22*AT22 = 2*2 + 5*5 = 29
Out23 = A21*AT13 + A22*AT23 = 2*3 + 5*6 = 36
Out31 = A31*AT11 + A32*AT21 = 3*1 + 6*4 = 27
Out32 = A31*AT12 + A32*AT22 = 3*2 + 6*5 = 36
Out33 = A31*AT13 + A32*AT23 = 3*3 + 6*6 = 45
Input
First line contains n and m, indicating that the matrix A is n by m.
Next, there will be n lines, each line will have m integers.
n m
A11 A12 ... A1m
A21 A22 ... A2m
... .
... .
... .
An1 ... ... Anm
Both n and m will be less than 10 and bigger than 1.
Output
Output the result of A multiplying with the transpose matrix of A.
Use "%5d" for each value.
Print newline at the end of each rows.
Tags