Euler's identity with angle in degrees

7 vues (au cours des 30 derniers jours)
Ali Kiral
Ali Kiral le 30 Juin 2023
Commenté : Ali Kiral le 30 Juin 2023
How can I get MATLAB to accept a in degress in exp(aj) to return a complex number where j^2=-1? By default the software takes a in radians.

Réponse acceptée

Torsten
Torsten le 30 Juin 2023
Modifié(e) : Torsten le 30 Juin 2023
a = 30;
exp(deg2rad(a)*1i)
ans = 0.8660 + 0.5000i
exp(a*pi/180*1i)
ans = 0.8660 + 0.5000i

Plus de réponses (2)

Joe Vinciguerra
Joe Vinciguerra le 30 Juin 2023
Modifié(e) : Joe Vinciguerra le 30 Juin 2023
[EDIT: oops. converted in the wrong direction.]
deg2rad will convert degrees to radians (https://www.mathworks.com/help/matlab/ref/deg2rad.html).
So you'll do something like this:
j = sqrt(-1);
a = 180;
exp(deg2rad(a)*j)
ans = -1.0000 + 0.0000i

Paul
Paul le 30 Juin 2023
If the input is given in degrees, consider writing your own function using cosd and sind for accurate results at the 90 deg intervals
e = @(x) cosd(x) + 1i*sind(x);
d = [90 180 270];
format long e
e(d)
ans =
0.000000000000000e+00 + 1.000000000000000e+00i -1.000000000000000e+00 + 0.000000000000000e+00i 0.000000000000000e+00 - 1.000000000000000e+00i
exp(d*pi/180*1i)
ans =
6.123233995736766e-17 + 1.000000000000000e+00i -1.000000000000000e+00 + 1.224646799147353e-16i -1.836970198721030e-16 - 1.000000000000000e+00i
  1 commentaire
Ali Kiral
Ali Kiral le 30 Juin 2023
That's cool Paul, thanks!

Connectez-vous pour commenter.

Produits


Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by