% function that calculates the trace of a matrix. It is the sum of the % diagonal elements of the matrix function traceval=trace_matrix(A) n=length(A); traceval=0; for i=1:n traceval=traceval+A(i,i); end