FOR FREE CONTENT

Find Trace and Normal of a Matrix

Back to Programming

Description

The normal of a matrix can be defined as the square root of the sum of squares of each element of the matrix.

The trace is the sum of the diagonal elements of a square matrix.

 

If the matrix be:

 

The normal of the matrix:

 

The trace of the matrix = 1+5+3 = 9

For finding the trace the matrix should be a square matrix.

Algorithm

INPUT: A matrix
OUTPUT: The trace and normal of the matrix

PROCESS:
Step 1: [taking the input]
	Read m, n [the number of rows and columns of the matrix]
	For i=0 to m-1 repeat
		For j=0 to n-1 repeat
			Read a[i][j]
		[End of ‘for’ loop]
	[End of ‘for’ loop]
Step 2: [Finding the trace and normal of the matrix]
	Set s1<-0
	Set s<-0
for i=0 to m-1 repeat 
for j=0 to n-1 repeat
Set s1<-s1+ a[i][j]2
		[End of ‘for’ loop]
	[End of ‘for’ loop]
	Set normal<-square root of s1
    	Print "The normal of the matrix is: normal”
    	for i = 0 to m-1 repeat 
        		Set s<-s+a[i][i]
    	[End of ‘for’ loop]
    	Print "Trace of the matrix is: s”
Step 3: Stop.


Code

Contributed by