How to write this script in complex conjugate, it should have real and imaginary values
1 view (last 30 days)
Show older comments
Balaji Ramdas
on 28 Nov 2021
Answered: Walter Roberson
on 28 Nov 2021
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 Comments
Walter Roberson
on 28 Nov 2021
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.
Accepted Answer
Walter Roberson
on 28 Nov 2021
r1source = sqrt( (reshape(y,[],1)-y1).^2) + (reshape(x,1,[])-x1).^2 + (reshape(z,1,1,[])-z1).^2 );
0 Comments
More Answers (0)
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!