简体   繁体   中英

Plotting complex functions in matlab

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM