首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java中矩阵的余因子(用于确定矩阵的逆)

Java中矩阵的余因子(用于确定矩阵的逆)
EN

Stack Overflow用户
提问于 2013-02-13 17:24:03
回答 2查看 2.5K关注 0票数 1

我正在尝试使用伴随方法来确定矩阵的逆矩阵,即(首先计算矩阵的余因子,然后转置这个矩阵,最后将其乘以(1/行列式)作为行列式的值的逆数)我有确定转置和行列式的方法,但是我正在努力处理余因子矩阵-

显示如何通过手动http://www.mathwords.com/i/inverse_of_a_matrix.htm使用伴随方法确定逆数的链接显示如何通过手动http://www.mathwords.com/c/cofactor_matrix.htm计算余因>

我有一个计算行列式和转置的方法,但是我不能让cofactor方法给出我需要的输出。

输出示例为=> 24 5 -4

24 5 -4

24 5 -4但是第二行和第三行应该是不同的,有什么建议吗?谢谢!下面是我使用的=>方法,checkIfSquare和assigningSign方法也工作得很好

代码语言:javascript
运行
复制
    public static int[][] cofactor(int[][] matrix) {
    int[][] cofactorMatrix = new int[matrix.length][matrix.length];

    for (int j = 0; j < matrix.length; j++) {
        if (checkIfSquare(matrix)) {
            for (int location = 0; location < matrix.length; location++) {
                int reducedMatrix[][] = new int[matrix.length - 1][matrix.length - 1];

                for (int rows = 1; rows < matrix.length; rows++) {
                    for (int cols = 0; cols < matrix.length; cols++) {
                        if (cols > location) {
                            reducedMatrix[rows - 1][cols - 1] = matrix[rows][cols];
                        } else if (cols < location) {
                            reducedMatrix[rows - 1][cols] = matrix[rows][cols];
                        }
                    }
                }

                int sign = assigningSign(location);
                cofactorMatrix[j][location] = determinantCalc(reducedMatrix) * sign;
            }
        }
    }
    return cofactorMatrix;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-13 17:45:02

在计算reducedMatrix时,您总是跳过第一行。这适用于余因子矩阵的第一行,但对于下面的行,您需要跳过第j行。这就是为什么您的输出由重复的第一行组成。

顺便说一句,这是一种可怕的计算矩阵逆的方法。我认为这只是一个学术练习,并不是用在严肃的程序中。

票数 1
EN

Stack Overflow用户

发布于 2013-02-13 17:41:27

没有必要重新发明轮子。Jama是一个写得很好的包。Maven存储库

代码语言:javascript
运行
复制
    <dependency>
        <groupId>Jama</groupId>
        <artifactId>Jama</artifactId>
        <version>1.0.2</version>
    </dependency>

    <repository>    
        <id>ebi-repo</id>    
        <name>The EBI internal repository</name>    
        <url>http://www.ebi.ac.uk/~maven/m2repo</url>    
        <releases>      
            <enabled>true</enabled>    
        </releases>    
        <snapshots>      
            <enabled>false</enabled>    
        </snapshots>  
    </repository>        

或者,可以在http://math.nist.gov/javanumerics/jama/#Package上找到jar文件

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14850173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档