필터 지우기
필터 지우기

If I have an array of 4 dimensions say A=complex(​rand(2,2,2​,2),rand(2​,2,2,2)). If I need to calculate the inverse of this matrix, as defined beow , how should I do it?

조회 수: 2 (최근 30일)
I need to compute B(x,y,z,w) such that if I multiply the terms of A and B , I should get an identity matrix I(a,b,c,d):
I=zeros(a,b,c,d);
for a=1:2
for b=1:2
for c=1:2
for d=1:2
for i=1:2
for j=1:2
I(a,b,c,d)=A(a,b,i,j)*B(i,j,c,d)+I(a,b,c,d);
end
end
end
end
end
end
The I(a,b,c,d)= 1 only when a=b=c=d
  댓글 수: 2
Matt J
Matt J 2016년 10월 21일
It is puzzling that you are organizing your data in 4D form, when you appear to want to do simple 2D matrix algebra with it. Are you sure it wouldn't be better just to reshape your data into 2D form
A=reshape(A,4,4)
and keep it that way?
vishav Rattu
vishav Rattu 2016년 10월 21일
편집: vishav Rattu 2016년 10월 21일
But if I reshape it, will I get the above B matrix that is required? That is, will B satisfy the above condition, that is I(a,b,c,d)=1 only if a=b=c=d? If I am able to get such a B, then I don't need to keep it in a 4d form.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2016년 10월 21일
[a,b,c,d]=ndgrid(1:2);
I=reshape(a==b & b==c & c==d, 4,4);
A=reshape(A,4,4);
B=reshape( A\I , 2,2,2,2);

추가 답변 (1개)

KSSV
KSSV 2016년 10월 21일
Are you looking for something like this?
A = rand(2,2,2,2) ;
B = zeros(2,2,2,2) ;
for i = 1:2
for j = 1:2
B(:,:,i,j) = inv(A(:,:,i,j)) ;
end
end
% check
for i = 1:2
for j = 1:2
A(:,:,i,j)*B(:,:,i,j)
end
end

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by