public static void Jacobi(MatrixR A, double tolerance, out MatrixR x, out VectorR lambda) { MatrixR AA = A.Clone(); int n = A.GetCols(); int maxTransform = 5 * n * n; MatrixR matrix = new MatrixR(n, n); MatrixR R = matrix.Identity(); MatrixR R1 = R; MatrixR A1 = A; lambda = new VectorR(n); x = R; double maxTerm = 0.0; int I, J; do { maxTerm = MaxTerm(A, out I, out J); Transformation(A, R, I, J, out A1, out R1); A = A1; R = R1; }while (maxTerm > tolerance); x = R; for (int i = 0; i < n; i++) { lambda[i] = A[i, i]; } for (int i = 0; i < n - 1; i++) { int index = i; double d = lambda[i]; for (int j = i + 1; j < n; j++) { if (lambda[j] > d) { index = j; d = lambda[j]; } } if (index != i) { lambda = lambda.GetSwap(i, index); x = x.GetColSwap(i, index); } } }