Question: Question is: For this program can anyone fix the line, MatrixOperations mo = new MatrixOperations(); because I am getting a warning that says MartixOperation is

Question is: For this program can anyone fix the line, "MatrixOperations mo = new MatrixOperations();" because I am getting a warning that says "MartixOperation is a raw type. References to generic type MartixOperation should be parameterized." I would like to fix and understand this warning so the program may run.

package Project1; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner;

class MatrixOperations { public Integer[][] addition(Integer[][] m1, Integer [][] m2) { Integer add[][] = new Integer[m1.length][m1[0].length]; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { add[i][j] = m1[i][j] + m2[i][j]; } } return add; } public Integer[][] subtraction(Integer[][] m1, Integer[][] m2) { Integer sub[][] = new Integer[m1.length][m1[0].length]; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { sub[i][j] = m1[i][j] - m2[i][j]; } } return sub; } // product of m1 and m2 public Integer[][] product(Integer[][] m1, Integer[][] m2) { Integer mul[][] = new Integer[m1.length][m2[0].length]; for(int i = 0; i < mul.length;i++) Arrays.fill(mul[i], 0); for(int i = 0; i < m1.length; i++) for(int j = 0; j < m2[0].length; j++) for(int k = 0; k < m1[0].length; k++) mul[i][j] = mul[i][j] + ( m1[i][k] * m2[k][j] ); return mul; } // finds the determinant of a matrix public Integer determinant(Integer a[][]) { if(a.length == 2) { return (a[0][0] * a[1][1]) - (a[1][0] * a[0][1]); } int det = 0; for(int i = 0; i < a.length; i++) det = det + (a[0][i] * ( a[1][(i+1)%3] * a[2][(i+2)%3] - a[1][(i+2)%3] * a[2][(i+1)%3] ) ); return det; } // prints the matrix with the given messgae into the file represented // the the stream public void print(String message, E a[][], PrintStream p) { p.println(message); for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) p.print("\t"+a[i][j]); p.println(""); } } // transpose of the matrix is calculated by interchanging the // rows with columns public Integer[][] transpose(Integer a[][]) { Integer T[][] = new Integer[a.length][a[0].length]; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) T[i][j] = a[j][i]; } return T; }

// finds and returns Inverse of a matrix Double[][] inverse(Integer[][] a) { Double[][] inverse = new Double[a.length][a.length]; double det = determinant(a); for(int i = 0; i < a.length; i++) { for(int j = 0; j < a.length; j++) inverse[i][j] = ((a[(j+1)%3][(i+1)%3] * a[(j+2)%3][(i+2)%3]) - (a[(j+1)%3][(i+2)%3] * a[(j+2)%3][(i+1)%3]))/ det; } return inverse; }

// returns the cofactor matrix of a // each value in cofactor matrix is calculated by removing the // respective row and column from the matrix and // calculating the determinant of the remaining 2X2 matrix Integer[][] cofactor(Integer[][] a) { Integer[][] cofactor = new Integer[a.length][a.length]; for(int i = 0; i < a.length; i++) { for(int j = 0; j < a[0].length; j++) { int cf = determinant(removeRowCol(a, i, j)); if(i != j && a.length-i != j) { cofactor[i][j] = cf; } else { cofactor[i][j] = -cf; } } } return cofactor; } Integer[][] removeRowCol(Integer a[][], int p, int q) { Integer[][] matrix = new Integer[a.length-1][a.length-1]; // Looping for each element of the matrix for (int row = 0, i = 0, j = 0; row < a.length; row++) { for (int col = 0; col < a.length; col++) { if (row != p && col != q) { matrix[i][j++] = a[row][col];

if (j == a.length - 1) { j = 0; i++; } } } } return matrix; } }

class StatisticalOperations { private int data[];

public StatisticalOperations() { }

public StatisticalOperations(int[] data) { this.data = data; } // sum of all elements of the data public int sum() { int sum = 0; for(int element : data) { sum += element; } return sum; } // average = sum of elements / no. of elements public double average() { return sum() / (data.length * 1.0); } // varience is the sum of squares of differences of // data elements with their average public double varience() { double avg = average(); double diff = 0; for(int ele : data) { diff += Math.pow(ele - avg, 2); } return diff/(data.length*1.0); }

// standard deviation is the square root of the varience double standardDeviation(int[] dElements) { return Math.sqrt(varience()); } }

class ProjectA_Main { public static void main(String args[]) throws FileNotFoundException { Scanner in = new Scanner(new File("Minput.txt")); PrintStream out = new PrintStream(new File("Moutput.txt")); MatrixOperations mo = new MatrixOperations(); Integer a[][] = new Integer[3][3]; Integer b[][] = new Integer[3][3]; Integer c[][];

// Reading input matices System.out.println("Reading matrix A"); for(int i = 0;i < 3; i++) for(int j = 0; j < 3; j++) a[i][j]=in.nextInt(); mo.print("Matrix A", a, System.out); mo.print("Matrix A", a, out); System.out.println("Reading matrix B"); for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) b[i][j]=in.nextInt(); mo.print("Matrix B", b, System.out); mo.print("Matrix B", b, out); in.close(); c = mo.addition(a, b); mo.print("Addition of A and B matrices is......", c, System.out); mo.print("Addition of A and B matrices is......", c, out); c = mo.product(a, b); mo.print("Multiplication of A and B matrices is......", c, System.out); mo.print("Multiplication of A and B matrices is......", c, out); Integer[][] transpose = mo.transpose(c); mo.print("Transpose of resultent matrix is......", transpose, System.out); mo.print("Transpose of resultent matrix is......", transpose, out); Integer[][] cofactor = mo.cofactor(c); mo.print("Cofactor matrix of resultent is......", cofactor, System.out); mo.print("Cofactor matrix of resultent is......", cofactor, out); double d = mo.determinant(a); System.out.println("Determinate of the A matrix is "+d); out.println("Determinate of the A matrix is "+d); Double inverseA[][] = mo.inverse(a); mo.print("Invarse matrix of A is......", inverseA, System.out); mo.print("Invarse matrix of A is......", inverseA, out); Integer firstCol[][] = new Integer[3][1]; for(int i = 0; i < 3; i++) { firstCol[i][0] = b[i][0]; } Integer multiply[][] = mo.product(a, firstCol); int dElements[] = new int[6]; for(int i = 0; i < 3; i++) { dElements[i] = a[i][i]; // diagonal elements of a and b dElements[i+3] = b[i][i]; } // find their standard deviation StatisticalOperations so = new StatisticalOperations(dElements); System.out.println("Standard deviation of diagonal elements is "+so.standardDeviation(dElements)); out.println("Standard deviation of diagonal elements is "+so.standardDeviation(dElements)); out.close(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!