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


    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 |

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

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

  • 相关阅读:
    Python 序列化处理
    httpclient
    java获取配置文件中变量值
    利用数据库管理工具(Navicat)导出数据到Excel表中
    如何确保发布的项目是最新的
    上传文件,重命名
    Mybatis plus中一个框多条件查询 SQL拼接
    用eclipse发布springboot项目
    使用SQL命令行更改数据库字段类型
    Java中查询某个日期下所有时间段的数据
  • 原文地址:https://www.cnblogs.com/ciscolee/p/13038082.html
Copyright © 2020-2023  润新知