zoukankan      html  css  js  c++  java
  • 求解矩阵特征值-determinant

    int cal_N_det(int a[MAX][MAX], int N){

        int det=0;

        int temp[MAX][MAX];

        int index, row, column, i, j;

        if(N==1){  // only one element

            return a[0][0];

            

        } else if(N==2){  // 2*2 matrix

            det=(a[0][0]*a[1][1]-a[0][1]*a[1][0]);

            return det;

            

        } else {

            for(index=0; index<N; index++){

                row = 0;

                column = 0;

                for(i=1; i<N; i++){    // abstract the target matrix while avoiding the column which index on.

                    for(j=0; j<N; j++){

                        if(j==index) {

                            continue;    // back to 'for'

                        }

                        temp[row][column] = a[i][j];

                        column++;

                        if(column==N-1){

                          row++;

                          column = 0;

                        }

                    }

                }

                det += a[0][index]*pow(-1,index)*cal_N_det(temp,N-1);   // core

          }

          return det;

        }

    }

  • 相关阅读:
    Feature fake , new view in comment.
    MeeGo Architect
    小米手机 怪诞行为经济学
    [转载]ten years as a programmer
    C++ 头文件
    关于AGILE/TDD 和传统的design
    你是否在开发正确的产品
    正确的创业
    MeeGo架构
    Unit Test
  • 原文地址:https://www.cnblogs.com/sushome/p/12565811.html
Copyright © 2011-2022 走看看