real and imaginary part of complex number

Hi,
I'm trying to get the real and imaginary part of a formular in a limited range of a parameter n.
how do I add in my formular
syms n real
imag (1i^n)
that 0 < n < 1 ?
Thanks a lot!

10 commentaires

How about:
assume(0<n<1) % after the first line
btw
imag (1i^n)
is
sin(pi*n/2)
Niclas
Niclas le 15 Juil 2019
@madhan ravi: thanks for the input , but Matlab still can't solve it this way.
@Bruno Loung: thank you for the solution. But is there no possibility how Matlab can calculate such problems? I'm interested in the way to solve it.
Torsten
Torsten le 15 Juil 2019
Modifié(e) : Torsten le 15 Juil 2019
Write
1i = exp(1i*pi/2)
and use
exp(1i*pi/2)^n = exp(1i*n*pi/2)
exp(1i*x) = cos(x)+1i*sin(x)
.
Bruno Luong
Bruno Luong le 15 Juil 2019
Modifié(e) : Bruno Luong le 15 Juil 2019
I'm interested in the way to solve it.
Just like Torsen's development. So you'll see that is true for any n that is real, the assumption that (0<n<1) is irrelevant.
Niclas
Niclas le 15 Juil 2019
Modifié(e) : Niclas le 15 Juil 2019
true. Torsten helped me with the understanding, thanks.
Now I get the way how to do it with a pencil. But what if the complex number gets much more complicated?
I still searching for a way to split real and imaginary part with Matlab.
Torsten
Torsten le 15 Juil 2019
Modifié(e) : Torsten le 15 Juil 2019
z^n = (r*exp(i*phi))^n = r^n * (cos(n*phi) + i*sin(n*phi))
Re(z^n) = r^n*cos(phi*n)
Im(z^n) = r^n*sin(phi*n)
z = r^n*(cos(n*phi)+1i*sin(n*phi))
Re = real(z)
Im = imag(z)
gives in my Matlab
Re =
real(r^n)*cos(n*phi) - imag(r^n)*sin(n*phi)
Im =
imag(r^n)*cos(n*phi) + real(r^n)*sin(n*phi)
these are obviously not the solutions you wrote and I'm looking for.
Torsten
Torsten le 15 Juil 2019
r is real - it is the length of the vector from the origin to z.
Thus
real(r^n) = r^n, imag(r^n) = 0.
yes, the two solutions are equal.
But how can I use Matlab to transform the equation?
If I give Matlab
imag(1I^n)
as complex number, why the program don't know how to transform it to polar coordinates? And why Matlab don't get from that
imag(r^n) = 0
?
If there any possibility to not do this transformation manually?

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 16 Juil 2019
V = complex(randi([-10 10],1), randi([-10 10])); %some data to work on
syms n real
Vn = V^(1/n);
RV = rewrite( real(Vn), 'exp');
IV = rewrite( imag(Vn), 'exp');

6 commentaires

Niclas
Niclas le 16 Juil 2019
Modifié(e) : Niclas le 16 Juil 2019
works perfect for this function, thanks!
I used it without the data to work on.
can I ask you a subsequent question? Why does this not work for (i*x)^n
syms x real
syms n real
Vn = ((1i*x)^n);
RV = rewrite( real(Vn), 'exp')
IV = rewrite( imag(Vn), 'exp')
I expected something like
RV=x^n*sin(pi/2*n)
IV=x^n*cos(pi/2*n)
but Matlab gave:
RV =real(exp(n*log(a))*exp((pi*n*1i)/2))
IV =imag(exp(n*log(a))*exp((pi*n*1i)/2))
Walter Roberson
Walter Roberson le 16 Juil 2019
Modifié(e) : Walter Roberson le 16 Juil 2019
Current versions of MATLAB give
RV =
exp(n*log(abs(x)))*cos(n*angle(x*1i))
IV =
exp(n*log(abs(x)))*sin(n*angle(x*1i))
If you can constrain x further then it can produce better results:
syms x positive
syms n real
Vn = ((1i*x)^n);
RV = rewrite( real(Vn), 'exp')
IV = rewrite( imag(Vn), 'exp')
Either way you might want to simplify(RV) and simplify(IV)
Niclas
Niclas le 16 Juil 2019
Modifié(e) : Niclas le 16 Juil 2019
really nice Walter, this works perfectly!
How about going one step further: it does not work with (1+(1i*x)^n)^y
syms x positive
syms y positive
syms n real
Vn = (1+(1i*x)^n)^y;
RV = simplify(rewrite( real(Vn), 'exp'))
IV = simplify(rewrite( imag(Vn), 'exp'))
I expected something like (take care, this is wrong!)
RV=1+x^n*y*cos(pi*n*y/2)
IV=x^n*sin(pi*n*y/2)
but only got
RV =real(((-1)^(n/2)*x^n + 1)^y)
IV =imag(((-1)^(n/2)*x^n + 1)^y)
. Is there an other possibility to expand this to get a solution like before?
Torsten
Torsten le 16 Juil 2019
Do you know of an expansion for (1+x)^y if x and y are real positive numbers except an infinite Taylor series ? I don't.
Good point Torsten.
I guess we need constrain y further. So why dont take the assumption from begin:
assume(0<y<1)
The Matlab solution stays the same.
Torsten
Torsten le 16 Juil 2019
y positive integer
might work.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by