nasiee
transpose
2 Answer(s)      a year and 9 months ago
Posted in : Java Beginners

how to write transpose of a matrix a program....

View Answers

August 16, 2011 at 1:21 PM


public class Transpose {

public static void main(String[] args) {

    // create N-by-N matrix
    int N = Integer.parseInt(args[0]);
    int[][] a = new int[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            a[i][j] = N*i + j;
        }
    }

    // print out initial matrix
    System.out.println("Before");
    System.out.println("------");
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            System.out.printf("%4d", a[i][j]);
        }
        System.out.println();
    }

    // transpose in-place
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            int temp = a[i][j];
            a[i][j] = a[j][i];
            a[j][i] = temp;
        }
    }

    // print out transposed matrix
    System.out.println();
    System.out.println("After");
    System.out.println("------");
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            System.out.printf("%4d", a[i][j]);
        }
        System.out.println();
    }

}

}


August 17, 2011 at 11:41 AM


import java.util.*;

public class Transpose {
        public static void main(String[] args) throws Exception {
                int rows, cols;
                int[][] matrix, tmatrix;
                Scanner input = new Scanner(System.in);
                System.out.print("Enter number of rows: ");
                rows = input.nextInt();
                System.out.print("Enter number of columns: ");
                cols = input.nextInt();
                matrix = new int[rows][cols];
                tmatrix = new int[cols][rows];
                System.out.println("Enter elements for Matrix");
                for (int i = 0; i < rows; i++) {
                        for (int j = 0; j < cols; j++) {
                                matrix[i][j] = input.nextInt();
                        }
                }
                for (int i = 0; i < rows; i++) {
                        for (int j = 0; j < cols; j++) {
                                tmatrix[i][j] = matrix[j][i];
                        }
                }
                System.out.println("Matrix is:");
                for (int i = 0; i < rows; i++) {
                        for (int j = 0; j < cols; j++) {
                                System.out.print(matrix[i][j] + " ");
                        }
                        System.out.println();
                }
                System.out.println("Its transpose is: ");
                for (int i = 0; i < cols; i++) {
                        for (int j = 0; j < rows; j++) {
                                System.out.print(tmatrix[i][j] + " ");
                        }
                        System.out.println();
                }
        }
}









Related Pages:
transpose
transpose  how to write transpose of a matrix a program
transpose of matrix
transpose of matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose
transpose matrix
transpose matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose of it. for this program u r given
Java Transpose of a matrix
Java Transpose of a matrix In this section, you will learn how to determine the transpose of a matrix.The transpose of a matrix is formed by interchanging... of the transposed matrix. The transpose of A is denoted by AT. Through the following
using array
using array  transpose a matrix
using array
using array  transpose a matrix
java applet
transpose. The web page should have two text boxes and a submit button labbeled... with the submit button labelled as Compute Transpose. When the Compute Transpose Button clicked , the transpose of the input matrix has to be displayed
java applet
transpose. The web page should have two text boxes and a submit button labbeled... with the submit button labelled as Compute Transpose. When the Compute Transpose Button clicked , the transpose of the input matrix has to be displayed
java programs
java programs  A union B, transpose of matric, denomination..., Transpose of matrix: import java.util.*; public class Transpose { public...(); } System.out.println("Its transpose
find eror inc++
) { cout<<"Matrix not square so Transpose not possible!"; } else...;<endl; } cout<<endl<<"Matrix Transpose: "<<endl<<
Java
] ) { // transpose the numbers inprocess = data[b]; data[b] = data[b+1]; data[b+1
Need help - Java Beginners
array as its argument, performs its transpose, and returns the transposed n * m...(); } } public int[][] transpose(int[][] arr) { int[][] temp = arr
finding the eigenvalues and eigenvector of n*n matrix in java
; rot[1][1] = c; transpose(rot, rotT, 2);// rotT=transpose(Rot) for (int i = 0; i < size; i... the transpose of A and puts it into B * * @param A * @param B
Java
] ) { // transpose the numbers inprocess = data[b]; data[b] = data[b+1]; data
programes on array
iv) find transpose of an matrix   1) import java.util.*; class...;Transpose of Matrix
questions
iv) find transpose of an matrix Q. 7 programes on strings

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.