weixin_41997508 2021-03-21 09:55 采纳率: 100%
浏览 122
已采纳

Java实现以下算法

(1)生成一个d∗L维矩阵(2)矩阵乘法(3)主要计算矩阵H的Moore-Penrose广义逆,它可以通过矩阵H与其转置矩阵HT相乘

  • 写回答

1条回答 默认 最新

  • piaoyiren 2021-03-21 10:25
    关注

    package juzhen;

    import java.util.Random;
    //1)生成一个d∗L维矩阵(2)矩阵乘法(3)主要计算矩阵H的Moore-Penrose广义逆,它可以通过矩阵H与其转置矩阵HT相乘


    public class JuZhen {
        public static Integer[][] getJuZhen(int d,int l){
            Integer results[][]=new Integer[d][l];
            Random random=new Random();
            for(int i=0;i<d;i++) {
                for(int j=0;j<l;j++) {
                    results[i][j]=random.nextInt(100);
                    System.out.print(results[i][j]+"    ");
                }
                System.out.println();
            }
            return results;
        }
        
        public static Integer[][] chengMethod(Integer[][] first,Integer[][] second){//求矩阵乘法
            int firstD=first.length;
            int firstL=first[0].length;
            int secondD=second.length;
            int secondL=second[0].length;
            Integer results[][]=new Integer[firstD][secondL];
            Integer firstLv[]=null;
            Integer secondDv=0;
            int j=0,m=0;
            int i=0,n=0,count=0;
            int temp=0;
                for(;i<firstD;) {
                    firstLv=first[i];
                    for(n=0;n<secondD;n++) {
                        secondDv=second[n][m];
                        temp+=firstLv[n]*secondDv;                    
                    }
                    results[i][m]=temp;
                    temp=0;
                    System.out.println(results[i][m]);
                    m++;
                    if(m==secondL) {
                        m=0;
                        i++;
                    }
                }
            return results;
        }
        public static Integer[][] zhuanzhi(Integer[][] juzhen){
            Integer m=juzhen.length;
            Integer n=juzhen[0].length;
            Integer results[][]=new Integer[n][m];
    //        for(int i=0;i<m;i++) {
    //            for(int j=0;j<n;j++) {
    //                System.out.print(juzhen[i][j] +"   ");
    //            }
    //            System.out.println();
    //        }
    //        System.out.println("-----------------------------");
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    results[i][j]=juzhen[j][i];
                    System.out.print(results[i][j]+"    ");
                }
                System.out.println();
            }
            return results;
        }
        public static void main(String[] args) {
            Integer first[][]= {{2,3,4},{3,4,5}};
            Integer second[][]= {{4,7},{5,3},{2,3}};
    //        chengMethod(first,second);
            Integer hInteger[][]=getJuZhen(3, 4);
            Integer results[][]=zhuanzhi(hInteger);
            chengMethod(hInteger, results);
    //        getJuZhen(3, 4);
        }
    }
     

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误