Source code for proj

'''
    .. todo::

        Add a modulus_squared function.
'''

import math


[docs]def sum_diff(a, b): ''' Calculate the sum and the difference of two variables. :param a: number :param b: number :return sum: sum of *a* and *b* :return diff: difference between *a* and *b* :: # Examples sum(1, 3) # output 4, -2 sum(1+1j, -1j) # output 1, 1+2j ''' sum = a + b diff = a - b return sum, diff
[docs]def modulus(z): r''' Calculate the modulus :math:`|z|` of a complex number :math:`z`. The modulus is given by: .. math:: |z| = \sqrt{[\Re(z)]^2+[\Im(z)]^2} :param z: complex number :return modulus: modulus of :math:`z` .. note:: Works for real variables too. ''' modulus = math.sqrt(z.real**2 + z.imag**2) return modulus