필터 지우기
필터 지우기

Performing an Operation on a Matrix Using Complex Numbers

조회 수: 1 (최근 30일)
MarshallSc
MarshallSc 2022년 1월 7일
편집: MarshallSc 2022년 1월 7일
I have a matrix with the operation perfomed as:
a = rand(10,10);
a_x = @(x) sum((x-a)./(x+a),'all');
aa = arrayfun(a_x,a);
I want the operation for each pair to be performed in complex format. For example for one pair of the matrix ( a(1) & a(2) ) points, it will be like:
complex(a(1),-a(2)) / complex(a(1),a(2)); %% a(1) - a(2)i / a(1) + a(2)i
Which will give me:
ans =
-0.0313 - 0.9995i
I want this operation (sum of all the relations for each point) to be performed for all the matrix components (may original matrix is 81*81).
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 1월 7일
To confirm, you want
complex(a(I,J),-a(K,L)) / complex(a(I,J),a(K,L));
for all I, J, and K, L? Including or excluding K,L = I,J ?
So you want (81 x 81) x (81 x 81) size output ?
MarshallSc
MarshallSc 2022년 1월 7일
Yessir, including K,L = I,J, since I need the sum for each point, they need to be included.
This will give me a (81 x 81) in complex form for the aa (summing every relation for each point, same as):
a_x = @(x) sum((x-a)./(x+a),'all');
The difference is the subtraction in the nominator and summation in the denominator will be like:
a_x = @(x) sum ((x - ai)./(x + ai), 'all'): % obviously this is not correct, just wanted to show what I mean

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

채택된 답변

Matt J
Matt J 2022년 1월 7일
편집: Matt J 2022년 1월 7일
sz=size(a);
C=(a(:)-1i*a(:).');
result=reshape(C./conj(C) , [sz,sz]);
  댓글 수: 4
MarshallSc
MarshallSc 2022년 1월 7일
편집: MarshallSc 2022년 1월 7일
The "result" should be transformed into a 10 x 10 complex double that each summation for each component is written in this way:
a(1) = a(1) - a(1)i / a(1) + a(1)i + a(1) - a(2)i / a(1) + a(2)i + ...
a(1) - a(3)i / a(1) + a(3)i + . . . + a(1) - a(n)i / a(1) + a(n)i
a(2) = a(2) - a(1)i / a(2) + a(1)i + a(2) - a(2)i / a(2) + a(2)i + ...
a(2) - a(3)i / a(2) + a(3)i + . . . + a(2) - a(n)i / a(2) + a(n)i
.
.
.
a(n) = a(n) - a(1)i / a(n) + a(1)i + a(n) - a(2)i / a(n) + a(2)i + ...
a(n) - a(3)i / a(n) + a(3)i + . . . + a(n) - a(n)i / a(n) + a(n)i
Matt J
Matt J 2022년 1월 7일
편집: Matt J 2022년 1월 7일
That would just be,
sum(result,[3,4])

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

추가 답변 (1개)

Matt J
Matt J 2022년 1월 7일
sz=size(a);
C=2*atan(a(:),a(:).');
result=reshape( exp(1j*C), [sz,sz]);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by