How to write this script in complex conjugate, it should have real and imaginary values

1 回表示 (過去 30 日間)
Results should have real and imaginary part in the form of (a+bi)
% Initilization
r1source = zeros(length(y),length(x),length(z)) ;
r2source = zeros(length(y),length(x),length(z)) ;
r3source = zeros(length(y),length(x),length(z)) ;
for m=1:length(y)
for n=1:length(x)
for o=1:length(z)
r1source(m,n,o)=sqrt((x(n)-x1)^2+(y(m)-y1)^2+(z(o)-z1)^2);
r2source(m,n,o)=sqrt((x(n)-x2)^2+(y(m)-y2)^2+(z(o)-z2)^2);
r3source(m,n,o)=sqrt((x(n)-x3)^2+(y(m)-y3)^2+(z(o)-z3)^2);
end
end
end
  4 件のコメント
Adam Danz
Adam Danz 2021 年 11 月 28 日
How do the a/b/c values map to the values in the last line?
Walter Roberson
Walter Roberson 2021 年 11 月 28 日
r1source(m,n,o)=sqrt((x(n)-x1)^2+(y(m)-y1)^2+(z(o)-z1)^2);
if x and x1 and y and y1 and z and z1 are all real-valued, then (x(n)-x1) and (y(m)-y1) and (z(o)-z1) will be real-valued, and the square of a real quantity is never negative, so the sum of squares would never be negative, so r1source would never be complex-valued.
For r1source to be complex-valued, at least one of the quantities would have to be complex-valued. If some of the quantities are real-valued but others are purely imaginary, then although the squares of the purely imaginary components would be negative, they might not be negative enough to balance the other parts, so you could end up with sqrt() of a positive number.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 11 月 28 日
r1source = sqrt( (reshape(y,[],1)-y1).^2) + (reshape(x,1,[])-x1).^2 + (reshape(z,1,1,[])-z1).^2 );

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by