sympy absolute value of complex exponential

  • Last Update :
  • Techknowledgy :

In general, to simplify things using complex numbers, use expand_complex, which tries to rewrite the expression as a + b*I, where a, and b are real. This works for me.

In[17]: (abs(exp(I))).expand(complex = True)
Out[17]:
   ___________________╱ 2 2╲╱ cos(1) + sin(1)

In[18]: simplify(abs(exp(I)).expand(complex = True))
Out[18]: 1

Suggestion : 2

This function return absolute value of a complex number. It is defined as the distance between the origin (0,0) and the point (a,b) in the complex plane. This function is an extension of the built-in function abs() to accept symbolic values.,This function returns conjugate of a complex number. To find the complex conjugate we change the sign of the imaginary part.,This function returns the largest integer value not greater than its argument. In case of complex numbers, this function too takes the floor of the real and imaginary parts separately.,This is a univariate function which returns the smallest integer value not less than its argument. In case of complex numbers, ceiling of the real and imaginary parts separately.

This function returns real part of an expression −

>>> from sympy
import *
>>>
re(5 + 3 * I)

5

>>> re(I)

This function returns imaginary part of an expression −

>>> im(5 + 3 * I)
  • I if im(expression) is positive
  • -I if im(expression) is negative
>>> sign(1.55), sign(-1), sign(S.Zero)

(1, -1, 0)

>>> sign(-3 * I), sign(I * 2)

Suggestion : 3

Sometimes, you need to have a unique symbol, for example as a temporary one in some calculation, which is going to be substituted for something else at the end anyway. This is achieved using Dummy("x"). So, to sum it up:,Introduction Installation SymPy's Architecture Functions Calculus Complex numbers Simplification Basic Operations Numerics Logical Operations Printing Solvers Common tasks ,We try to make the sources easily understandable, so you can look into the sources and read the doctests, it should be well documented and if you don�t understand something, ask on the mailinglist.,All symbolic things are implemented using subclasses of the Basic class. First, you need to create symbols using Symbol("x") or numbers using Integer(5) or Float(34.3). Then you construct the expression using any class from SymPy. For example Add(Symbol("a"), Symbol("b")) gives an instance of the Add class. You can call all methods, which the particular class supports.

a = Symbol("a")
b = Symbol("b")
e = (a + b) ** 2
print e
>>> from sympy import Add
>>> from sympy.abc import x
>>> e = Add(x, x)
>>> e
2*x

>>> type(e)
<class 'sympy.core.mul.Mul'>
>>> from sympy
import Symbol, Dummy
   >>>
   Symbol("x") == Symbol("x")
True

   >>>
   Dummy("x") == Dummy("x")
False
[user @localhost]: SYMPY_DEBUG = True. / bin / isympy

Suggestion : 4

This is an extension of the built-in function abs() to accept symbolic values. If you pass a SymPy expression to the built-in abs(), it will pass it automatically to Abs().,Return, if possible, the minimum value of the list. It is named Min and not min to avoid conflicts with the built-in function min.,Returns imaginary part of expression. This function performs only elementary analysis and so it will fail to decompose properly more complicated expressions. If completely simplified result is needed then use Basic.as_real_imag() or perform complex expansion on instance of this function.,Returns real part of expression. This function performs only elementary analysis and so it will fail to decompose properly more complicated expressions. If completely simplified result is needed then use Basic.as_real_imag() or perform complex expansion on instance of this function.

>>> from sympy
import re, im, I, E
   >>>
   from sympy.abc
import x, y
   >>>
   re(2 * E)
2 * E >>>
   re(2 * I + 17)
17
   >>>
   re(2 * I)
0
   >>>
   re(im(x) + x * I + 2)
2
>>> from sympy
import re, im, E, I
   >>>
   from sympy.abc
import x, y
   >>>
   im(2 * E)
0
   >>>
   re(2 * I + 17)
17
   >>>
   im(x * I)
re(x) >>>
   im(re(x) + y)
im(y)
>>> from sympy.functions
import im
   >>>
   from sympy
import I
   >>>
   im(2 + 3 * I).as_real_imag()
   (3, 0)
>>> from sympy.functions
import sign
   >>>
   from sympy.core.numbers
import I
>>> sign(-1) -
   1 >>>
   sign(0)
0
   >>>
   sign(-3 * I) -
   I >>>
   sign(1 + I)
sign(1 + I) >>>
   _.evalf()
0.707106781186548 + 0.707106781186548 * I
>>> from sympy
import Abs, Symbol, S
   >>>
   Abs(-1)
1
   >>>
   x = Symbol('x', real = True) >>>
   Abs(-x)
Abs(x) >>>
   Abs(x ** 2)
x ** 2 >>>
   abs(-x) # The Python built - in
Abs(x)