Volume of a matrix
For a complex matrix \(A\) with \(\operatorname{rank}(A)=r>0\), the volume of \(A\), denoted by \(\operatorname{vol}(A)\), is the product of \(r\) nonzero singular values of \(A\) or equivalently the square root of the sum of squares of modulus of all \(r\times r\) minors of \(A\).
#define vol quickly as the product of singular values
def vol(M):
M = matrix(CDF, M)
U, S, V = M.SVD() # Perform SVD
singular_values = S.diagonal() # Get the singular values (diagonal of S)
print('vol(M)=',prod(singular_values))
#an example
Mtranspose=matrix(CC,[[sqrt(3+4*i),-sqrt(3-4*i),0,0,0,0],[0,-sqrt(-2*i),sqrt(2*i),0,0,0],[-2,0,2,0,0,0],[0,0,1,-1,0,0],[0,0,0,sqrt(1+i),-sqrt(1-i),0],[0,0,0,0,3,-3],[0,0,0,-sqrt(-3-4*i),0,sqrt(-3+4*i)]])
M=transpose(Mtranspose)
vol(M)
An alternative way with more detailed calculations:
#define volume as the square root of the sum of squares of modulus of all rxr minors of a matrix of rank r; show the detailed calculations
def vol(M):
n=M.nrows()
m=M.ncols()
r=M.rank()
setn=[]
for i in range(n):
setn.append(i)
RS = Subsets(setn,r,submultiset=True)
setm=[]
for i in range(m):
setm.append(i)
CS = Subsets(setm,r,submultiset=True)
print('rank(M)=',r) #do not print if not needed
v=0
for s in RS:
for t in CS:
print('|det(M(',[x+1 for x in s],',',[x+1 for x in t],'))|^2=',(abs(det(M[s,t])))^2) #do not print this if you do not need the detailed claculations
v=v+(abs(det(M[s,t])))^2
print('vol^2(M)=',v) #do not print if not needed
print('vol(M)=',sqrt(v))
#an example
Mtranspose=matrix(CC,[[sqrt(3+4*i),-sqrt(3-4*i),0,0,0,0],[0,-sqrt(-2*i),sqrt(*i),0,0,0],[-2,0,2,0,0,0],[0,0,1,-1,0,0],[0,0,0,sqrt(1+i),-sqrt(1-i),0],[0,0,0,0,3,-3],[0,0,0,-sqrt(-3-4*i),0,sqrt(-3+4*i)]])
M=transpose(Mtranspose)
vol(M)