How i can exp(I*x) -->  cos(x)+I*sin(x)   ?

I wrote the following for personnal use :



def ThisIsEulerFormula(t):
    """
    Return t, but in a simplified form.


We force Sage to see that exp(ix) is equal to cos(x)+i*sin(x) and then to simplify the trigonometric expressions.

    INPUT :

    - ``t`` - a complex number

    OUTPUT:

    a complex number that is equal to t.

    EXAMPLE::

        sage: var('x')
        x
        sage: a=exp(I*x)
        sage: a.simplify_trig()
        e^(I*x)
        sage: ThisIsEulerFormula(a)
        I*sin(x) + cos(x)

    This is useful for detecting that an expression is real::

        sage: var('x')
        x
        sage: c=exp(I*x)+exp(-I*x)
        sage: c.simplify_trig()
        (e^(2*I*x) + 1)*e^(-I*x)
        sage: ThisIsEulerFormula(c)
        2*cos(x)

    NOTE:
    I think that the point is that Sage does not know that x is real.
    """

    return (t.real_part()+I*t.imag_part()).simplify_trig()



Hope that helps

Laurent

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to