一个4×4的矩阵,有什么快速的方法求它的最大特征值 ,或者是它的模?
一个4×4的矩阵,有什么快速的方法求它的最大特征值 ,或者是它的模?
[解决办法]
这是我以前做AHP的时候用过的一个程序片断,由于需要所以把特征向量规一化了:
- C# code
public class solution { private double v; private double [] weight; public solution(double v, double [] weight) { this.v = v; this.weight = weight; } public double V { get { return this.v; } set { this.v = value; } } public double [] Weight { get { return this.weight; } set { this.weight = value; } } } /// <summary> /// 幂法求矩阵最大特征根和特征向量实现 /// </summary> /// <param name="matrix"></param> /// <returns></returns> public static solution GetSolution(double [][] matrix) { double [] DL = new double[matrix.Length]; double [] tmp = new double[matrix.Length]; double [] tmp1 = new double[matrix.Length]; for (int i = 0; i < matrix.Length; i++) tmp[i] = 1; do { DL = tmp; double max = Max(tmp); for (int i = 0; i < tmp.Length; i++) tmp1[i] = tmp[i] / max; tmp = mMultiply(matrix, tmp1); }while(Math.Abs(Max(tmp) - Max(DL)) > 0.000001); DL = tmp; double maxVL = Max(DL); double sum = 0.0; foreach (double d in DL) sum += d; for (int i = 0; i < DL.Length; i++) DL[i] /= sum; return new solution(maxVL, DL); }