How to write this script in complex conjugate, it should have real and imaginary values
Show older comments
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
Adam Danz
on 28 Nov 2021
It will return compex numbers with imaginary components only if there are negative values within the square root. Please review the concept of imaginary numbers to understand how they are created.
Balaji Ramdas
on 28 Nov 2021
Edited: Walter Roberson
on 28 Nov 2021
Adam Danz
on 28 Nov 2021
How do the a/b/c values map to the values in the last line?
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
More Answers (0)
Categories
Find more on Number Theory 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!