This is a Java Program which calculates the normal of a given matrix. |
package codingcorner.in; import java.util.Scanner; public class NormalMatrix { public static void main(String[] args) { double sum = 0; int rows, columns, i, j; double normal; Scanner scan = new Scanner(System.in); System.out.print("Enter order of matrix : \t"); rows = scan.nextInt(); columns = scan.nextInt(); int matrix[][] = new int[rows][columns]; System.out.print("Enter elements of the matrix :\n"); for (i = 0; i < rows; i++) { for (j = 0; j < columns; j++) { System.out.print("Enter element m" + (i + 1) + (j + 1) + ":\t"); matrix[i][j] = scan.nextInt(); } } scan.close(); System.out.print("\n\nMATRIX is :\n"); for (i = 0; i < rows; i++) { for (j = 0; j < columns; j++) System.out.print(matrix[i][j] + "\t"); System.out.print("\n"); } System.out.print("\n\nIts NORMAL is:\n"); for (j = 0; j < columns; j++) { for (i = 0; i < rows; i++) sum = sum + Math.pow(matrix[i][j], 2); } normal = Math.sqrt(sum); System.out.print(normal); } }
OUTPUT :
Java - Normal of a matrix |