I have the following code
x = linspace(-pi, pi, 1e3);
y = sqrt((x).^(1/2));
plot(x, real(y));
plot(x, imag(y));
The value at x=-1 on the real and imaginary plots are both 0.7071 (sqrt(0.5). Why is it not 0 (real) and 1 (imaginary)? When I enter this code:
real((-1)^(1/2))
imag((-1)^(1/2))
this gives me 0 (real) and 1 (imaginary) as expected.
Any help would be much appreciated. Thanks,
Note that sqrt((x).^(1/2)) = x.^(1/4)
This is not all imaginary since (-i)^4 = i^4 = -1*-1 = 1
. Consider what happens on the complex plane and you should be able to arrive at the conclusion that if y^4 = -1
then y = exp(i*(2*N-1)*pi/4)
where N
is any integer.
This leads to 4 unique solutions for y
which are +/-sqrt(2)/2 +/- i*sqrt(2)/2
. MATLAB returns the one where both real and imaginary are positive.