English 中文(简体)
Matlab-Matrix - Trace
  • 时间:2024-09-17

Matlab-Matrix - Trace


Previous Page Next Page  

Trace helps you to calculate the sum of diagonal elements in a given matrix.

Example

Consider the given 3x3 matrix. Let us find out the sum of diagonal elements as shown below −


a = [ 1 2 3; 2 3 4; 1 2 5];
test = trace(a)

Output

The execution in MATLAB is as follows −


>> a = [ 1 2 3; 2 3 4; 1 2 5]
test = trace(a)

a =

   1  2  3
   2  3  4
   1  2  5
 
test =

   9
   
>>
Advertisements