public virtual void CalculateFirstEigenValueAndEigenVector(MatrixObject A, Vector InitialValueForEigenVector, out double EighenValue, out Vector EigenVector) { //Set X equal to initial eigenvector Vector X = InitialValueForEigenVector; X.MakeThisAUnitVector(); EighenValue = 1.0d;; //Hold old eigenvalue double OldEigenvalue = 0.0d; //Use power method to iteratively calculate eigenvalue and eigenvector for (int i = 0; i < MaximumNumberOfIterations; i++) { NumberOfIterations++; Vector Z = A.MultiplyByVectorU(X); EighenValue = Vector.DotProduct(X, Z); Z.MakeThisAUnitVector(); X = Z; double DeltaLambda = EighenValue - OldEigenvalue; UpdateDeltaEigenValues(DeltaLambda); OldEigenvalue = EighenValue; if (i > NumberOfEigenValueChangesChecked - 1) { if (ArrayTools.Vector_Magnitude(DeltaEigenValues) < Precision) { EigenVector = X; return; } } } EigenVector = X; return; }
public virtual void CalculateFirstEigenValueAndEigenVector(MatrixObject A, out double EighenValue, out Vector EigenVector) { //Set X equal to the eigenvector Vector X = new Vector(A.n); //Initialize X to a vector with all components the same X.SetComponentsEqualToUnity(); CalculateFirstEigenValueAndEigenVector(A, X, out EighenValue, out EigenVector); }