Convert a Complex Number to exponential real

Hi
I am looking for help to calculate value of a complex number say x = 2 +1j*5 using exponential function
Thanks you

 Réponse acceptée

Hi Jogger,
have a look at Euler's formula (https://en.wikipedia.org/wiki/Euler's_formula).
x = 2 + 1j * 5;
r = sqrt(real(x)^2 + imag(x)^2);
phi = atan2(imag(x),real(x));
fprintf(1,'z = r * exp(j*phi)\nr = %.2f\nphi = %.2f',r,phi)
z = r * exp(j*phi) r = 5.39 phi = 1.19
Kind regards,
Robert

Plus de réponses (1)

dpb
dpb le 16 Juin 2021
MATLAB has builtin functions abs (or hypot()) and angle() for the above explicit implementations...
>> x=complex(2,5);
>> cmplx2exp=@(x) deal(abs(x),angle(x));
>> [r,theta]=cmplx2exp(x)
r =
5.3852
theta =
1.1903
>>

3 commentaires

Life is Wonderful
Life is Wonderful le 16 Juin 2021
Modifié(e) : Life is Wonderful le 17 Juin 2021
Thanks a lot Robert U and dpb
I make it little simpler
x = pi;
% complex number
(1) exp(1i*pi)
-1.0000 + 0.0000i
OR
% complex number
(1) exp(complex(0,pi))
-1.0000 + 0.0000i
% Real number
(2) exp(pi)
23.1407
% Side note, exponential is inverse of logarithm
>> log(23.1407)
ans =
3.1416 % get back the input value
I want to know how exp(1i*pi) is mapped to exp(pi) so that I know the input value is same !
OR
convert multivalue to single value . By doing , one can determine logarithm ( single value )
Thanks
Life is Wonderful
Life is Wonderful le 17 Juin 2021
Modifié(e) : Life is Wonderful le 17 Juin 2021
I have written a script and can someone explain the correctness
x = [-2*pi:1:2*pi];
y = exp(x);
z = log(y);
y1= exp(1i*x) ;
z1= (log(1i*y1));
fprintf('%10s\t| %10s\t|%10s\t| %15s%+15s| %15s%+15s|\n------------+---------------+-----------+---------------+---------------+---------------+---------------+\n','x(i)', 'exp(i)', 'log(i)', 'expreal(y1(i))','expimag(y1(i))','logreal(z1(i))','logimag(z1(i))');
for i = 1:length(x)
fprintf('%10f\t| %10.5f\t|%10f\t| %15f%+15f| %15f%+15f|\n',x(i), y(i), z(i), real(y1(i)),imag(y1(i)),real(z1(i)),imag(z1(i)));
end
Life is Wonderful
Life is Wonderful le 17 Juin 2021
Modifié(e) : Life is Wonderful le 17 Juin 2021
I ma having following output
x(i) | exp(i) | log(i) | expreal(y1(i)) expimag(y1(i))| logreal(z1(i)) logimag(z1(i))|
----------------+---------------+---------------+---------------+---------------+---------------+---------------+
-6.283185 | 0.00187 | -6.283185 | 1.000000 +0.000000| 0.000000 +1.570796|
-5.283185 | 0.00508 | -5.283185 | 0.540302 +0.841471| -0.000000 +2.570796|
-4.283185 | 0.01380 | -4.283185 | -0.416147 +0.909297| 0.000000 -2.712389|
-3.283185 | 0.03751 | -3.283185 | -0.989992 +0.141120| 0.000000 -1.712389|
-2.283185 | 0.10196 | -2.283185 | -0.653644 -0.756802| -0.000000 -0.712389|
-1.283185 | 0.27715 | -1.283185 | 0.283662 -0.958924| -0.000000 +0.287611|
-0.283185 | 0.75338 | -0.283185 | 0.960170 -0.279415| -0.000000 +1.287611|
0.716815 | 2.04790 | 0.716815 | 0.753902 +0.656987| 0.000000 +2.287611|
1.716815 | 5.56677 | 1.716815 | -0.145500 +0.989358| 0.000000 -2.995574|
2.716815 | 15.13205 | 2.716815 | -0.911130 +0.412118| -0.000000 -1.995574|
3.716815 | 41.13316 | 3.716815 | -0.839072 -0.544021| -0.000000 -0.995574|
4.716815 | 111.81153 | 4.716815 | 0.004426 -0.999990| 0.000000 +0.004426|
5.716815 | 303.93525 | 5.716815 | 0.843854 -0.536573| -0.000000 +1.004426|

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Coder dans Centre d'aide et File Exchange

Produits

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by