임의의 정사각형 행렬의 결정 계산 다음 matlab에 테스트 스크립트 참조 (matlab에 내장 된 기능에 대한 비교도 포함되어 있습니다) :
nMin = 2; % Start with 2-by-2 matrices
nMax = 50; % Quit with 50-by-50 matrices
nTests = 10000;
detsOfL = NaN*zeros(nTests, nMax - nMin + 1);
detsOfA = NaN*zeros(nTests, nMax - nMin + 1);
disp(' ');
for n = nMin:nMax
tStart = tic;
for j = 1:nTests
A = randn(n, n);
detA1 = det(A); % Matlab's built-in function
if n == 1
detsOfL(j, 1) = 1;
detsOfA(j, 1) = A;
continue; % Trivial case => Quick return
end
[L, U, P] = lu(A);
PtL = P'*L;
realEigenvaluesOfPtL = real(eig(PtL));
if min(prod(realEigenvaluesOfPtL)) < 0 % det(L) is always +1 or -1
detL = -1;
else
detL = 1;
end
detU = prod(diag(U));
detA2 = detL * detU; % Determinant of A using LU decomposition
if detA1 ~= detA2
error(['Determinant computation failed at n = ' num2str(n) ', j = ' num2str(j)]);
end
detsOfL(j, n - nMin + 1) = detL;
detsOfA(j, n - nMin + 1) = detA2;
end
tElapsed = toc(tStart);
disp(sprintf('Determinant computation was successful for n = %d!! Elapsed time was %.3f seconds', n, tElapsed));
end
disp(' ');
얼마나 큰 행렬은? 얼마나 많은 결정 인자를 계산하고 싶습니까? –
행렬이 매우 큽니다 (N> 22는 충분히 클 것입니까?). 그리고 얼마나 많이? 주어진 행렬에 대한 단 하나의 결정자. 입력 : 1 큰 매트릭스 출력 : 입력 매트릭스에 대한 단일 결정입니다. –
숫자 안정성도 문제가됩니까? – Henry