transpose

transpose

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 Tutorials/Questions & Answers:
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
Advertisements
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
ModuleNotFoundError: No module named 'transpose'
ModuleNotFoundError: No module named 'transpose'  Hi, My Python... 'transpose' How to remove the ModuleNotFoundError: No module named 'transpose' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'transpose-dict'
ModuleNotFoundError: No module named 'transpose-dict'  Hi, My... named 'transpose-dict' How to remove the ModuleNotFoundError: No module named 'transpose-dict' error? Thanks   Hi, In your python
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
[][] {{4,3,1,2},{1,1,1,1},{1,2,1,1},{1,1,1,1} }; double t, c, s; int p, q, icount..., rowOfElMax, maxElRow); q = rowOfElMax[0]; p = colRowOfElMax[q]; icount = 0; state = 1; // Iterations while
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...: System.out.println("Invalid Entry!"); } } while (!quit); } }   Transpose
questions
questions   Q. 1 programes on if....else 1. write a program... (adsbygoogle = window.adsbygoogle || []).push({}); Q. 2 programes on switch.... write a program to print no of days in a given month Q. 3 programes on while

Ads