Search code examples
maxima

Maxima: Expand e to cos and i sin?


Is there a function in Maxima to expand complex exponentials to cos + i sin form by Euler?

e.g.

expr: %e^(%i*w);
trigsomefunctionplease(expr);

that would give...

(%o1) cos(w) + i sin(w)

?


Solution

  • This is Euler's formula and not de Moivre's formula, but in Maxima there is a function and an option-variable called demoivre to accomplish this.

    Function: demoivre (expr)
    Option variable: demoivre
    The function demoivre (expr) converts one expression without setting the global variable demoivre.

    When the variable demoivre is true, complex exponentials are converted into equivalent expressions in terms of circular functions: exp (a + b*%i) simplifies to %e^a * (cos(b) + %i*sin(b)) if b is free of %i. a and b are not expanded.

    The default value of demoivre is false.

    exponentialize converts circular and hyperbolic functions to exponential form. demoivre and exponentialize cannot both be true at the same time.

    Here is an example using the Maxima Online Calculator

    (%i1) demoivre;
    (%o1)                                false
    (%i2) %e^(%i*w);
                                          %i w
    (%o2)                               %e
    (%i3) expr:%e^(%i*w);
                                          %i w
    (%o3)                               %e
    (%i4) demoivre(%e^(%i*w));
    (%o4)                         %i sin(w) + cos(w)
    (%i5) demoivre(expr);
    (%o5)                         %i sin(w) + cos(w)
    (%i6) %e^(%i*w),demoivre=true;
    (%o6)                         %i sin(w) + cos(w)
    (%i7) expr,demoivre=true;
    (%o7)                         %i sin(w) + cos(w)
    (%i8) %e^(%i*w);
                                          %i w
    (%o8)                               %e
    (%i9) demoivre:true;
    (%o9)                                true
    (%i10) %e^(%i*w);
    (%o10)                        %i sin(w) + cos(w)
    (%i11) expr;
                                          %i w
    (%o11)                              %e
    (%i12) expr,ev;
    (%o12)                        %i sin(w) + cos(w)
    (%i13)