package com.math; /** * Matrix * @author ciscolee * */ public class MathMatrix { public static void main(String[] args) { /** * |1 2 3 | * |4 5 6 | * |7 8 9 | */ double [][] martix = new double[3][3]; double x=0; System.out.println("存在这样一个矩阵:"); for (int i = 0; i < 3; i++) { System.out.print("|"); for (int j = 0; j < 3; j++) { x=x+1; martix[i][j]=x; System.out.print(martix[i][j]+" "); } System.out.println("|"); } System.out.println("他的转置矩阵:"); new TMatrix(3,3, martix); } } //求转置矩阵 class TMatrix{ int rows; int cols; double [][]matrix; public TMatrix(int rows,int cols,double[][]martix) { double mid; if (rows==cols) for ( int i= 0; i <rows; i++) { for (int j = 0; j <cols; j++) { if(i!=j&&i<j){//这里的条件判断很关键,你品,你细品!!!! mid=martix[i][j]; martix[i][j]=martix[j][i]; martix[j][i]=mid; } } } for (int i = 0; i < martix.length; i++) { System.out.print("|"); for (int j = 0; j < martix.length; j++) { System.out.print(martix[i][j]+" "); } System.out.println("|"); } } }
存在这样一个矩阵:
|1.0 2.0 3.0 |
|4.0 5.0 6.0 |
|7.0 8.0 9.0 |
他的转置矩阵:
|1.0 4.0 7.0 |
|2.0 5.0 8.0 |
|3.0 6.0 9.0 |
以上是转置矩阵的求法、及打印结果。
后面矩阵的可逆矩阵、单位矩阵、矩阵乘法、加法等,以及行列式求法等后续再贴上