2.12 Find the product of elements in a matrix along the diagonal

Mathematica

mat= {{1, 2, 3}, 
      {4, 5, 6}, 
      {7, 8, 9}} 
Apply[Times,Diagonal[mat]]
 

Out[49]= 45

 

Matlab

A=[1 2 3; 
   4 5 6; 
   7 8 9] 
prod(diag(A))
 

ans = 45

 

Maple

restart; 
A:=Matrix([[1,2,3],[4,5,6],[7,8,9]]); 
d:=MTM:-diag(A); 
mul(x,x in d); 
 
#or simpler is 
restart; 
A:=Matrix([[1,2,3],[4,5,6],[7,8,9]]); 
mul(LinearAlgebra:-Diagonal(A));
 

45