지수가? 아니, 매트릭스 반전은 O (N^3)라고 생각합니다.
행렬 방정식을 풀려면 LU decomposition을 사용하는 것이 좋습니다. 행렬식을 사용할 때이를 결정할 필요는 없습니다.
아직 도움이되는 패키지를 살펴보십시오. JAMA이 떠오른다.
12x12 또는 19x19는 큰 matricies가 아닙니다. 자유도가 수십 또는 수백이되는 수천의 문제를 해결하는 것이 일반적입니다.
다음은 JAMA 사용 방법의 실제 예입니다.
package linearalgebra;
import Jama.LUDecomposition;
import Jama.Matrix;
public class JamaDemo
{
public static void main(String[] args)
{
double [][] values = {{1, 1, 2}, {2, 4, -3}, {3, 6, -5}}; // each array is a row in the matrix
double [] rhs = { 9, 1, 0 }; // rhs vector
double [] answer = { 1, 2, 3 }; // this is the answer that you should get.
Matrix a = new Matrix(values);
a.print(10, 2);
LUDecomposition luDecomposition = new LUDecomposition(a);
luDecomposition.getL().print(10, 2); // lower matrix
luDecomposition.getU().print(10, 2); // upper matrix
Matrix b = new Matrix(rhs, rhs.length);
Matrix x = luDecomposition.solve(b); // solve Ax = b for the unknown vector x
x.print(10, 2); // print the solution
Matrix residual = a.times(x).minus(b); // calculate the residual error
double rnorm = residual.normInf(); // get the max error (yes, it's very small)
System.out.println("residual: " + rnorm);
}
}
여기 quant_dev의 권고에 따라, 아파치 코 몬즈 수학을 사용하여 해결했다 동일한 문제입니다 :
package linearalgebra;
import org.apache.commons.math.linear.Array2DRowRealMatrix;
import org.apache.commons.math.linear.ArrayRealVector;
import org.apache.commons.math.linear.DecompositionSolver;
import org.apache.commons.math.linear.LUDecompositionImpl;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.RealVector;
public class LinearAlgebraDemo
{
public static void main(String[] args)
{
double [][] values = {{1, 1, 2}, {2, 4, -3}, {3, 6, -5}};
double [] rhs = { 9, 1, 0 };
RealMatrix a = new Array2DRowRealMatrix(values);
System.out.println("a matrix: " + a);
DecompositionSolver solver = new LUDecompositionImpl(a).getSolver();
RealVector b = new ArrayRealVector(rhs);
RealVector x = solver.solve(b);
System.out.println("solution x: " + x);;
RealVector residual = a.operate(x).subtract(b);
double rnorm = residual.getLInfNorm();
System.out.println("residual: " + rnorm);
}
}
를 상황에 이러한 적응 컴파일하고 실행하면 당신은 당신의 CLASSPATH에서 JAMA의 JAR을 가지고 있습니다.
@duffymo : 답변 해 주셔서 감사합니다. 당신이 옳습니다, 기하 급수적으로 말이 아닙니다. 행렬 크기 12x12에서 행렬식을 계산하는 데 걸리는 시간이 눈에 띄게 증가한다는 것을 의미합니다. 나는 Jama를 사용해 봤지만, 제대로 작동하지 않는다. (나는 Java에서 꽤 새로운 것이다.) LU 분해에 대해서도 살펴볼 것입니다. 감사합니다. . – dedalo
알고리즘이 실제로 지수 함수이기 때문에 "기하 급수적으로"정확하지 않지만, 역행렬 또는 행렬식 계산이 * 지수 *를 요구하지 않는다는 점에서 Duffymo 또한 정확합니다. – JaakkoK
감사합니다. 나는 Jama를보고 클래스 Matrix에서 'det'이라는 메서드를 찾았습니다.이 메서드는이를 빠르게 계산합니다.나는 또한 행렬 L과 U (A = L * U)를 계산하고 det (A) = det (L) * det (U)를 계산하는 방법을 찾았다. – dedalo