Example #1
0
def c8_div_r8(c1, r2):

    #*****************************************************************************80
    #
    ## C8_DIV_R8 divides a C8 by an R8.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    12 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C1, real R2, the values.
    #
    #    Output, complex VALUE, the function value.
    #
    from c8_real import c8_real
    from c8_imag import c8_imag

    a = c8_real(c1) / r2
    b = c8_imag(c1) / r2

    value = a + b * 1j

    return value
Example #2
0
def c8_conj(c):

    #*****************************************************************************80
    #
    ## C8_CONJ evaluates the conjugate of a C8.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    11 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C, the argument.
    #
    #    Output, complex VALUE, the function value.
    #
    from c8_imag import c8_imag
    from c8_real import c8_real

    value = c8_real(c) - 1j * c8_imag(c)

    return value
Example #3
0
def c8_to_cartesian(c):

    #*****************************************************************************80
    #
    ## C8_TO_CARTESIAN converts a C8 to cartesian form.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    13 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C, the value.
    #
    #    Output, real X, Y, the cartesian form.
    #
    from c8_imag import c8_imag
    from c8_real import c8_real

    x = c8_real(c)
    y = c8_imag(c)

    return x, y
def c8_exp ( c ):

#*****************************************************************************80
#
## C8_EXP evaluates the exponential of a C8.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    11 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, complex C, the argument.
#
#    Output, complex VALUE, the function value.
#
  import numpy as np
  from c8_real import c8_real
  from c8_imag import c8_imag

  cr = c8_real ( c );
  ci = c8_imag ( c );

  value = np.exp ( cr ) * ( np.cos ( ci ) + np.sin ( ci ) * 1j );

  return value
Example #5
0
def c8_conj ( c ):

#*****************************************************************************80
#
## C8_CONJ evaluates the conjugate of a C8.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    11 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, complex C, the argument.
#
#    Output, complex VALUE, the function value.
#
  from c8_imag import c8_imag
  from c8_real import c8_real

  value = c8_real ( c ) - 1j * c8_imag ( c )

  return value
Example #6
0
def c8_div_r8 ( c1, r2 ):

#*****************************************************************************80
#
## C8_DIV_R8 divides a C8 by an R8.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    12 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, complex C1, real R2, the values.
#
#    Output, complex VALUE, the function value.
#
  from c8_real import c8_real
  from c8_imag import c8_imag

  a = c8_real ( c1 ) / r2
  b = c8_imag ( c1 ) / r2

  value = a + b * 1j

  return value
def c8_to_cartesian ( c ):

#*****************************************************************************80
#
## C8_TO_CARTESIAN converts a C8 to cartesian form.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    13 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, complex C, the value.
#
#    Output, real X, Y, the cartesian form.
#
  from c8_imag import c8_imag
  from c8_real import c8_real

  x = c8_real ( c )
  y = c8_imag ( c )

  return x, y
Example #8
0
def c8_le_li ( c1, c2 ):

#*****************************************************************************80
#
## C8_LE_LI := C1 <= C1 for C8's, and the Loo norm.
#
#  Discussion:
#
#    The Loo norm can be defined here as:
#
#      C8_NORM_LI(C) = max ( abs ( real (C) ) + abs ( imag (C) ) )
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    19 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, complex C1, C2, the values to be compared.
#
#    Output, boolean VALUE, is TRUE if C1 <= C2.
#
  from c8_imag import c8_imag
  from c8_real import c8_real

  if ( max ( abs ( c8_real ( c1 ) ), abs ( c8_imag ( c1 ) ) ) \
    <= max ( abs ( c8_real ( c2 ) ), abs ( c8_imag ( c2 ) ) ) ) :
    value = True
  else:
    value = False

  return value
def c8_le_l1(c1, c2):

    #*****************************************************************************80
    #
    ## C8_LE_L1 := C1 <= C1 for C8's, and the L1 norm.
    #
    #  Discussion:
    #
    #    The L1 norm can be defined here as:
    #
    #      C8_NORM_L1(C) = abs ( real (C) ) + abs ( imag (C) )
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    19 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C1, C2, the values to be compared.
    #
    #    Output, boolean VALUE, is TRUE if C1 <= C2.
    #
    from c8_imag import c8_imag
    from c8_real import c8_real

    if ( abs ( c8_real ( c1 ) ) + abs ( c8_imag ( c1 ) ) \
      <= abs ( c8_real ( c2 ) ) + abs ( c8_imag ( c2 ) ) ) :
        value = True
    else:
        value = False

    return value
def c8_div(c1, c2):

    #*****************************************************************************80
    #
    ## C8_DIV divides two C8's.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    12 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C1, C2, the values.
    #
    #    Output, complex VALUE, the function value.
    #
    from c8_real import c8_real
    from c8_imag import c8_imag

    a = c8_real(c1)
    b = c8_imag(c1)
    c = c8_real(c2)
    d = c8_imag(c2)

    e = c * c + d * d

    f = (a * c + b * d) / e
    g = (b * c - a * d) / e

    value = f + g * 1j

    return value
Example #11
0
def c8_div(c1, c2):

    # *****************************************************************************80
    #
    ## C8_DIV divides two C8's.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    12 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C1, C2, the values.
    #
    #    Output, complex VALUE, the function value.
    #
    from c8_real import c8_real
    from c8_imag import c8_imag

    a = c8_real(c1)
    b = c8_imag(c1)
    c = c8_real(c2)
    d = c8_imag(c2)

    e = c * c + d * d

    f = (a * c + b * d) / e
    g = (b * c - a * d) / e

    value = f + g * 1j

    return value
def c8_mul(c1, c2):

    #*****************************************************************************80
    #
    ## C8_MUL multiplies two C8's.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    12 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C1, C2, the values.
    #
    #    Output, complex VALUE, the function value.
    #
    from c8_real import c8_real
    from c8_imag import c8_imag

    a1 = c8_real(c1)
    b1 = c8_imag(c1)
    a2 = c8_real(c2)
    b2 = c8_imag(c2)

    a3 = a1 * a2 - b1 * b2
    b3 = a1 * b2 + b1 * a2

    value = a3 + b3 * 1j

    return value
Example #13
0
def c8_mul ( c1, c2 ):

#*****************************************************************************80
#
## C8_MUL multiplies two C8's.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    12 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, complex C1, C2, the values.
#
#    Output, complex VALUE, the function value.
#
  from c8_real import c8_real
  from c8_imag import c8_imag

  a1 = c8_real ( c1 )
  b1 = c8_imag ( c1 )
  a2 = c8_real ( c2 )
  b2 = c8_imag ( c2 )

  a3 = a1 * a2 - b1 * b2
  b3 = a1 * b2 + b1 * a2

  value = a3 + b3 * 1j

  return value
Example #14
0
def c8_nint(c):

    # *****************************************************************************80
    #
    ## C8_NINT returns the nearest complex integer of a C8.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    15 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, complex C1, the value to be NINT'ed.
    #
    #    Output, complex VALUE, the NINT'ed value.
    #
    from math import floor
    from c8_real import c8_real
    from c8_imag import c8_imag
    from c8_mag import c8_mag

    xc = c8_real(c)
    yc = c8_imag(c)
    #
    #  Lower left.
    #
    x = floor(xc)
    y = floor(yc)
    r = (x - xc) ** 2 + (y - yc) ** 2
    r_min = r
    x_min = x
    y_min = y
    #
    #  Lower right.
    #
    x = floor(xc) + 1.0
    y = floor(yc)
    r = (x - xc) ** 2 + (y - yc) ** 2
    if r < r_min:
        r_min = r
        x_min = x
        y_min = y
    #
    #  Upper right.
    #
    x = floor(xc) + 1.0
    y = floor(yc) + 1.0
    r = (x - xc) ** 2 + (y - yc) ** 2
    if r < r_min:
        r_min = r
        x_min = x
        y_min = y
    #
    #  Upper left.
    #
    x = floor(xc)
    y = floor(yc) + 1.0
    r = (x - xc) ** 2 + (y - yc) ** 2
    if r < r_min:
        r_min = r
        x_min = x
        y_min = y

    value = x_min + 1j * y_min

    return value