Normal and Trace of a Matrix in Java
In this section, we will learn how to calculate the normal and trace of a matrix in Java. Before moving to, the program, first we will understand the what is normal and trace of a matrix.
Normal of a Matrix
The normal of a matrix is the square root of the sum of squares of all the elements of a matrix. For example, consider the following matrix.
First, we will calculate the sum of the square of each element.
92 + 82 + 22 + 12 + 42 + 72 + 32 + 52 + 62
81 + 64 + 4 + 1 + 16 + 49 + 9 + 25 + 36 = 285
Now, calculate the square root of the sum of squares.
√285 = 16.8819430161
Trace of a Matrix
The trace of a matrix is the sum of all the elements present in the principal diagonal (upper left to lower right). Note that the matrix must be a square matrix (the number of rows and columns must be the same). It is useful to prove results in linear algebra. For example, consider the following matrix.
Trace for the above matrix is 5 + 4 + 7 = 16.
Java Program to Find Normal and Trace of a Matrix
Similarly, we can also find the normal and trace of a matrix using function.