How can I specify a symmetric matrix so that MATLAB does not need to create and store the redundant symmetric part?

조회 수: 3 (최근 30일)
I have an N-by-N symmetric matrix that is very large and requires a large amount of memory to store. However, of the "N^2" elements in the matrix, "N*(N - 1)/2" are redundant. I would like to be able to create and operate on this symmetric matrix without ever having to create and store the entire N-by-N matrix.
LAPACK supports this type of matrix storage, and is referred to as a "packed" matrix.
I also have another sparse symmetric matrix and would like to store only half of it as opposed to the entire matrix.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
The ability to store and operate on only the significant part of a symmetric or a sparse symmetric matrix is not available in MATLAB.
The following symmat2vec.m function extracts and stores the significant part of an N-by-N symmetric matrix within a "N*(N + 1)/2"-by-1 vector. However, you will not be able to operate on this vector as a symmetric matrix without recreating the entire N-by-N symmetric matrix using the following vec2symmat.m function.
function V = symmat2vec(A)
% Converts a symmetric matrix "A" to a vector "V" of its significant part
N = size(A, 1);
V = zeros(N/2*(N + 1), 1);
I = [0 cumsum(1:N)];
for m = 1:N
V(I(m)+1:I(m + 1)) = A(1:m, m);
end
function A = vec2symmat(V)
% Converts vector "V" to an N-by-N matrix "A"
n = length(V);
N = (-1 + sqrt(1 + 8*n))/2;
A = zeros(N);
I = [0 cumsum(1:N)];
for m = 1:N
A(1:m, m) = V(I(m)+1:I(m + 1));
end
% Insert symmetric part
for m = 1:N-1
A(m+1:N, m) = A(m, m+1:N).';
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by