首页 > 编程语言 > 详细

java实现转置矩阵【有关矩阵后续在此续载】

时间:2020-06-03 16:46:29      阅读:42      评论:0      收藏:0      [点我收藏+]
技术分享图片
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("|");
        }
    }
    
}
View Code

存在这样一个矩阵:
|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 |

以上是转置矩阵的求法、及打印结果。

后面矩阵的可逆矩阵、单位矩阵、矩阵乘法、加法等,以及行列式求法等后续再贴上

java实现转置矩阵【有关矩阵后续在此续载】

原文:https://www.cnblogs.com/ciscolee/p/13038082.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!