Details of this Paper

trace of a square matrix is the sum of

Description

solution


Question

2. (Trace, 10pt) The trace of a square matrix is the sum of its diagonal elements. For example, the trace of the left matrix below is 1 + 0 + 6 = 7, and the trace of the 4x4 matrix on the right is 1+5-2-3 = 1.;Write a function trace(M) which calculates the trace of a matrix M. Matrices are given as two-dimensional lists. You can assume that the matrix is a square matrix, that is, the number of rows is the same as the number of columns. Below are two sample runs for the matrices above.

 

Paper#64994 | Written in 18-Jul-2015

Price : $27
SiteLock