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;

        }

    }

  • 相关阅读:
    从Pycharm说起
    前端工程师小A学习JS的旅程
    模板引擎开发(一)
    Bootstrap01
    Passbook详解与开发案例
    DLL文件知多少?
    C#中的索引器的简单理解和用法
    python 的列表遍历删除
    Node.js与Golang使用感受与小结1
    解决设计中的两难问题
  • 原文地址:https://www.cnblogs.com/sushome/p/12565811.html
Copyright © 2011-2022 走看看