Question: Task 9: Multiply Two Matrices Task 10: Transpose of a Matrix Create a static method named transposeMatrix which accepts a 3 x 3 integer matrix
Task 9: Multiply Two Matrices
Task 10: Transpose of a Matrix
Create a static method named transposeMatrix which accepts a 3 x 3 integer matrix and returns a new 3 x 3 matrix which is the result of switching the rows with the columns in the parameter matrix . Call this method and display the original matrix and the returned matrix.
uIf we switch the rows with the columns in a matrix the resulting new matrix is the Transpose of the original matrix.
Task 11: Symmetric Matrix
Create a static method named isSymmetricMatrix which accepts a 3 x 3 integer matrix and returns true if the matrix is symmetric and false otherwise . Call this method and display the returned boolean value.
A matrix is symmetric if the transpose of the matrix is the same as the original matrix
Task 12: Trace of a Matrix
Create a static method named traceMatrix which accepts a 3 x 3 integer matrix and returns the trace of the matrix. Call this method and display the returned value.
The trace of a matrix is the sum of the values on the main diagonal
Task 13: Determinant of a 3 x 3 Matrix
Create a static method named determinant3x3Matrix which accepts a 3 x 3 integer matrix and returns the determinant of the matrix. Call this method and display the returned value.
The determinant of a 3 x 3 matrix is calculated by:
det(M) = (A x E x I) + (B x F x G) + (C x D x H) (C x E x G) (B x D x I) (A x F x H)
Task 14: Powers of a Matrix
Create a static method named powerNMatrix which accepts a 3 x 3 integer matrix and an integer value and returns a new matrix which is the parameter matrix raised to the power of the parameter integer. Call this method and display the returned matrix.
uM3 = M x M x M
This is what I have so far from the previous tasks:
Task 1 : Display Matrix
public static displaymatrix(int[][] M)
{
for(int i=0;i { for(int j=0;j { System.out.println(M[i][j]+" "); } } Task 2 : Creat a Matrix public static int[][] buildMatrix(int v[]) { int res[3][3]; static int k=0; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { res[i][j]=v[k]; k++; } } return res; } Task 3: Create a Matrix public static int[][] buildRandomMatrix() { int[3][3] rmatrix; for (int i=0; i<3; i++) { for (int j=0; j<3; j++){ rmatrix[i][j] = (int) (Math.random()*10); } } return rmatrix } 4.Create a Matrix public static int[][] buildVectorMatrix(int[] a ,int[] b,int[] c) { int res[3][3],k=0; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { if(i==0) res[i][j]=a[k++]; if(i==1) res[i][j]=b[k++]; if(i==2) res[i][j]=c[k++]; } } Task 5: Compare Two Matrices public static bool compareMatrices(int[][] M,int[][] N) { } Task 6: Add two matrices public static int[][] addMatrices(int[] M,int[] N) { int C[][] = new int[3][3]; for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) C[i][j] = M[i][j] + N[i][j]; return C; } Task 7: Subtract two matrices public static int[][] subtractMatrices(int[] M,int[] N) { int C[][] = new int[3][3]; for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) C[i][j] = M[i][j] - N[i][j]; return C; } Task 8: Scalar Multiplication of Matrices public static scalarProductMatrix(int[][] M,int scalarvalue) { for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) M[i][j] = M[i][j] * scalarvalue; return M; } System.out.println();
int flag = 1; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (M[i][j] != N[i][j]) flag = 0; if (flag == 1) return true; else return false;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
