Example #1
0
def bab_inverse(n, alpha, beta):

    #*****************************************************************************80
    #
    ## BAB_INVERSE returns the inverse of the BAB matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    14 December 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Input, real ALPHA, BETA, the parameters.
    #
    #    Output, real A(N,N), the matrix.
    #
    from sys import exit
    import numpy as np
    from cheby_u_polynomial import cheby_u_polynomial
    from r8_mop import r8_mop

    a = np.zeros((n, n))

    if (beta == 0.0):

        if (alpha == 0.0):
            print ''
            print 'BAB_INVERSE - Fatal error!'
            print '  ALPHA = BETA = 0.'
            exit('BAB_INVERSE - Fatal error!')

        for i in range(0, n):
            a[i, i] = 1.0 / alpha

    else:

        x = 0.5 * alpha / beta

        u = cheby_u_polynomial(n, x)

        for i in range(1, n + 1):
            for j in range(1, i + 1):
                a[i - 1,
                  j - 1] = r8_mop(i + j) * u[j - 1] * u[n - i] / u[n] / beta
            for j in range(i + 1, n + 1):
                a[i - 1,
                  j - 1] = r8_mop(i + j) * u[i - 1] * u[n - j] / u[n] / beta

    return a
Example #2
0
def bab_inverse ( n, alpha, beta ):

#*****************************************************************************80
#
## BAB_INVERSE returns the inverse of the BAB matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    14 December 2014
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Input, real ALPHA, BETA, the parameters.
#
#    Output, real A(N,N), the matrix.
#
  from sys import exit
  import numpy as np
  from cheby_u_polynomial import cheby_u_polynomial
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  if ( beta == 0.0 ):

    if ( alpha == 0.0 ):
      print ''
      print 'BAB_INVERSE - Fatal error!'
      print '  ALPHA = BETA = 0.'
      exit ( 'BAB_INVERSE - Fatal error!' )

    for i in range ( 0, n ):
      a[i,i] = 1.0 / alpha

  else:

    x = 0.5 * alpha / beta

    u = cheby_u_polynomial ( n, x )

    for i in range ( 1, n + 1 ):
      for j in range ( 1, i + 1 ):
        a[i-1,j-1] = r8_mop ( i + j ) * u[j-1] * u[n-i] / u[n] / beta
      for j in range ( i + 1, n + 1 ):
        a[i-1,j-1] = r8_mop ( i + j ) * u[i-1] * u[n-j] / u[n] / beta

  return a
Example #3
0
def oto_inverse(n):

    #*****************************************************************************80
    #
    ## OTO_INVERSE returns the inverse of the OTO matrix.
    #
    #  Formula:
    #
    #    if ( I <= J )
    #      A(I,J) = (-1)^(I+J) * I * (N-J+1) / (N+1)
    #    else
    #      A(I,J) = (-1)^(I+J) * J * (N-I+1) / (N+1)
    #
    #  Example:
    #
    #    N = 4
    #
    #             4 -3  2 -1
    #    (1/5) * -3  6 -4  2
    #             2 -4  6 -3
    #            -1  2 -3  4
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    18 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of A.
    #
    #    Output, real A(N,N), the matrix.
    #
    import numpy as np
    from r8_mop import r8_mop

    a = np.zeros((n, n))

    for i in range(0, n):
        for j in range(0, n):
            if (i <= j):
                a[i, j] = r8_mop(i + j) * float(
                    (i + 1) * (n - j)) / float(n + 1)
            else:
                a[i, j] = r8_mop(i + j) * float(
                    (j + 1) * (n - i)) / float(n + 1)

    return a
Example #4
0
def oto_inverse ( n ):

#*****************************************************************************80
#
## OTO_INVERSE returns the inverse of the OTO matrix.
#
#  Formula:
#
#    if ( I <= J )
#      A(I,J) = (-1)^(I+J) * I * (N-J+1) / (N+1)
#    else
#      A(I,J) = (-1)^(I+J) * J * (N-I+1) / (N+1)
#
#  Example:
#
#    N = 4
#
#             4 -3  2 -1
#    (1/5) * -3  6 -4  2
#             2 -4  6 -3
#            -1  2 -3  4
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    18 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):
      if ( i <= j ):
        a[i,j] = r8_mop ( i + j ) * float ( ( i + 1 ) * ( n - j ) ) / float ( n + 1 )
      else:
        a[i,j] = r8_mop ( i + j ) * float ( ( j + 1 ) * ( n - i ) ) / float ( n + 1 )


  return a
Example #5
0
def lotkin_inverse ( n ):

#*****************************************************************************80
#
## LOTKIN_INVERSE returns the inverse of the LOTKIN matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    27 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from r8_choose import r8_choose
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):

      if ( j == 0 ):

        a[i,j] = r8_mop ( n - i - 1 ) \
          * r8_choose ( n + i, i ) \
          * r8_choose ( n, i + 1 )

      else:

        a[i,j] = r8_mop ( i - j + 1 ) * float ( i + 1 ) \
          * r8_choose ( i + j + 1, j ) \
          * r8_choose ( i + j, j - 1 ) \
          * r8_choose ( n + i, i + j + 1 ) \
          * r8_choose ( n + j, i + j + 1 )

  return a
Example #6
0
def lotkin_inverse(n):

    #*****************************************************************************80
    #
    ## LOTKIN_INVERSE returns the inverse of the LOTKIN matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    27 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of A.
    #
    #    Output, real A(N,N), the matrix.
    #
    import numpy as np
    from r8_choose import r8_choose
    from r8_mop import r8_mop

    a = np.zeros((n, n))

    for i in range(0, n):
        for j in range(0, n):

            if (j == 0):

                a[i,j] = r8_mop ( n - i - 1 ) \
                  * r8_choose ( n + i, i ) \
                  * r8_choose ( n, i + 1 )

            else:

                a[i,j] = r8_mop ( i - j + 1 ) * float ( i + 1 ) \
                  * r8_choose ( i + j + 1, j ) \
                  * r8_choose ( i + j, j - 1 ) \
                  * r8_choose ( n + i, i + j + 1 ) \
                  * r8_choose ( n + j, i + j + 1 )

    return a
Example #7
0
def gk323_determinant ( n ):

#*****************************************************************************80
#
## GK323_DETERMINANT computes the determinant of the GK323 matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    08 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real VALUE, the determinant.
#
  from r8_mop import r8_mop

  value = r8_mop ( n - 1 ) * 2.0 ** ( n - 2 ) * ( n - 1 )

  return value
Example #8
0
def cheby_van3_determinant ( n ):

#*****************************************************************************80
#
## CHEBY_VAN3_DETERMINANT computes the determinant of the CHEBY_VAN3 matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    08 January 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real DETERM, the determinant.
#
  from r8_mop import r8_mop
  from math import sqrt

  determ = r8_mop ( n + 1 ) * sqrt ( float ( n ) ** n ) / sqrt ( 2.0 ** ( n - 1 ) )
 
  return determ
Example #9
0
def hankel_n_determinant ( n ):

#*****************************************************************************80
#
## HANKEL_N_DETERMINANT computes the determinant of the HANKEL_N matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    11 January 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real DETERM, the determinant.
#
  from math import floor
  from r8_mop import r8_mop

  determ = r8_mop ( floor ( n / 2 ) ) * ( n ** n )

  return determ
Example #10
0
def hankel_n_determinant(n):

    #*****************************************************************************80
    #
    ## HANKEL_N_DETERMINANT computes the determinant of the HANKEL_N matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    11 January 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real DETERM, the determinant.
    #
    from math import floor
    from r8_mop import r8_mop

    determ = r8_mop(floor(n / 2)) * (n**n)

    return determ
Example #11
0
def forsythe_determinant ( alpha, beta, n ):

#*****************************************************************************80
#
## FORSYTHE_DETERMINANT computes the determinant of the FORSYTHE matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    04 February 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, real ALPHA, BETA, parameters that define the matrix.
#
#    Input, integer N, the order of the matrix.
#
#    Output, real VALUE, the determinant.
#
  from r8_mop import r8_mop

  value = r8_mop ( n - 1 ) * alpha + beta ** n

  return value
Example #12
0
def forsythe_determinant(alpha, beta, n):

    #*****************************************************************************80
    #
    ## FORSYTHE_DETERMINANT computes the determinant of the FORSYTHE matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    04 February 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, real ALPHA, BETA, parameters that define the matrix.
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real VALUE, the determinant.
    #
    from r8_mop import r8_mop

    value = r8_mop(n - 1) * alpha + beta**n

    return value
Example #13
0
def oto_eigen_right ( n ):

#*****************************************************************************80
#
## OTO_EIGEN_RIGHT returns the right eigenvectors of the OTO matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    19 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Output, real A(N,N), the right eigenvector matrix.
#
  import numpy as np
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):
      angle = float ( ( i + 1 ) * ( j + 1 ) ) * np.pi / float ( n + 1 )
      a[i,j] = r8_mop ( i + j ) * np.sqrt ( 2.0 / float ( n + 1 ) ) * np.sin ( angle )

  return a
Example #14
0
def cheby_van3_determinant(n):

    #*****************************************************************************80
    #
    ## CHEBY_VAN3_DETERMINANT computes the determinant of the CHEBY_VAN3 matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    08 January 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real DETERM, the determinant.
    #
    from r8_mop import r8_mop
    from math import sqrt

    determ = r8_mop(n + 1) * sqrt(float(n)**n) / sqrt(2.0**(n - 1))

    return determ
Example #15
0
def bernstein_to_power(n):

    #*****************************************************************************80
    #
    ## BERNSTEIN_TO_POWER returns the Bernstein-to-Power matrix.
    #
    #  Discussion:
    #
    #    The Bernstein-to-Power matrix of degree N is an N+1xN+1 matrix A which can
    #    be used to transform the N+1 coefficients of a polynomial of degree N
    #    from a vector B of Bernstein basis polynomial coefficients ((1-x)^n,...,x^n).
    #    to a vector P of coefficients of the power basis (1,x,x^2,...,x^n).
    #
    #    If we are using N=4-th degree polynomials, the matrix has the form:
    #
    #      1   0   0   0  0
    #     -4   4   0   0  0
    #      6 -12   6   0  0
    #     -4  12 -12   4  0
    #      1  -4   6  -4  1
    #
    #   and a polynomial with the Bernstein basis representation
    #     p(x) = 3/4 * b(4,1) + 1/2 b(4,2)
    #   whose Bernstein coefficient vector is
    #     B = ( 0, 3/4, 1/2, 0, 0 )
    #   will have the Bernstein basis coefficients
    #     P = A * B = ( 0, 3, -6, 3, 0 ).
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    16 March 2016
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the degree of the polynomials.
    #
    #    Output, real A(N+1,N+1), the Bernstein-to-Power matrix.
    #
    import numpy as np
    from r8_choose import r8_choose
    from r8_mop import r8_mop

    a = np.zeros([n + 1, n + 1])

    for j in range(0, n + 1):
        for i in range(0, j + 1):
            a[n-i,n-j] = r8_mop ( j - i ) * r8_choose ( n - i, j - i ) \
              * r8_choose ( n, i )

    return a
Example #16
0
def bernstein_matrix(n):

    #*****************************************************************************80
    #
    ## BERNSTEIN_MATRIX returns the Bernstein matrix.
    #
    #  Discussion:
    #
    #    The Bernstein matrix of order N is an NxN matrix A which can be used to
    #    transform a vector of power basis coefficients C representing a polynomial
    #    P(X) to a corresponding Bernstein basis coefficient vector B:
    #
    #      B = A * C
    #
    #    The N power basis vectors are ordered as (1,X,X^2,...X^(N-1)) and the N
    #    Bernstein basis vectors as ((1-X)^(N-1), X*(1-X)^(N-2),...,X^(N-1)).
    #
    #  Example:
    #
    #    N = 5
    #
    #    1    -4     6    -4     1
    #    0     4   -12    12    -4
    #    0     0     6   -12     6
    #    0     0     0     4    -4
    #    0     0     0     0     1
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    15 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real A(N,N), the Bernstein matrix.
    #
    import numpy as np
    from r8_choose import r8_choose
    from r8_mop import r8_mop

    a = np.zeros((n, n))

    for j in range(0, n):
        for i in range(0, j + 1):
            a[i,j] = r8_mop ( j - i ) * r8_choose ( n - 1 - i, j - i ) \
              * r8_choose ( n - 1, i )

    return a
Example #17
0
def bernstein ( n ):

#*****************************************************************************80
#
## BERNSTEIN returns the BERNSTEIN matrix.
#
#  Discussion:
#
#    The Bernstein matrix of order N is an NxN matrix A which can be used to
#    transform a vector of power basis coefficients C representing a polynomial 
#    P(X) to a corresponding Bernstein basis coefficient vector B:
#
#      B = A * C
#
#    The N power basis vectors are ordered as (1,X,X^2,...X^(N-1)) and the N 
#    Bernstein basis vectors as ((1-X)^(N-1), X*(1_X)^(N-2),...,X^(N-1)).
#
#  Example:
#
#    N = 5
#
#    1    -4     6    -4     1
#    0     4   -12    12    -4
#    0     0     6   -12     6
#    0     0     0     4    -4
#    0     0     0     0     1
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    15 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real A(N,N), the Bernstein matrix.
#
  import numpy as np
  from r8_choose import r8_choose
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  for j in range ( 0, n ):
    for i in range ( 0, j + 1 ):
      a[i,j] = r8_mop ( j - i ) * r8_choose ( n - 1 - i, j - i ) \
        * r8_choose ( n - 1, i )

  return a
Example #18
0
def sylvester_kac_eigen_right(n):

    #*****************************************************************************80
    #
    ## SYLVESTER_KAC_EIGEN_RIGHT: right eigenvectors of the SYLVESTER_KAC matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    14 April 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real V(N,N), the right eigenvectors.
    #
    import numpy as np
    from r8_mop import r8_mop

    b = np.zeros(n - 1)
    for i in range(0, n - 1):
        b[i] = float(i + 1)

    c = np.zeros(n - 1)
    for i in range(0, n - 1):
        c[i] = float(n - 1 - i)

    v = np.zeros((n, n))

    for j in range(0, n):

        lam = -n + 1 + 2 * j

        a = np.zeros(n)
        a[0] = 1.0
        a[1] = -lam
        for i in range(2, n):
            a[i] = -lam * a[i - 1] - b[i - 2] * c[i - 2] * a[i - 2]

        bot = 1.0
        v[0, j] = 1.0
        for i in range(1, n):
            bot = bot * b[i - 1]
            v[i, j] = r8_mop(i) * a[i] / bot

    return v
def sylvester_kac_eigen_right ( n ):

#*****************************************************************************80
#
## SYLVESTER_KAC_EIGEN_RIGHT: right eigenvectors of the SYLVESTER_KAC matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    14 April 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real V(N,N), the right eigenvectors.
#
  import numpy as np
  from r8_mop import r8_mop

  b = np.zeros ( n - 1 )
  for i in range ( 0, n - 1 ):
    b[i] = float ( i + 1 )

  c = np.zeros ( n - 1 )
  for i in range ( 0, n - 1 ):
    c[i] = float ( n - 1 - i )

  v = np.zeros ( ( n, n ) )

  for j in range ( 0, n ):

    lam = - n + 1 + 2 * j

    a = np.zeros ( n )
    a[0] = 1.0
    a[1] = - lam
    for i in range ( 2, n ):
      a[i] = - lam * a[i-1] - b[i-2] * c[i-2] * a[i-2]

    bot = 1.0
    v[0,j] = 1.0
    for i in range ( 1, n ):
      bot = bot * b[i-1]
      v[i,j] = r8_mop ( i ) * a[i] / bot

  return v
Example #20
0
def boothroyd_inverse ( n ):

#*****************************************************************************80
#
## BOOTHROYD_INVERSE returns the inverse of the BOOTHROYD matrix.
#
#  Example:
#
#    N = 5
#
#      5   -10    10    -5     1
#    -15    40   -45    24    -5
#     35  -105   126   -70    15
#    -70   224  -280   160   -35
#    126  -420   540  -315    70
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    24 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from r8_choose import r8_choose
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):

      a[i,j] = r8_mop ( i + j ) * r8_choose ( n + i, i ) \
        * r8_choose ( n-1, n-j-1 ) * float ( n  ) / float ( i + j + 1 )

  return a
def bernstein_to_legendre(n):

    #*****************************************************************************80
    #
    ## BERNSTEIN_TO_LEGENDRE returns the Bernstein-to-Legendre matrix.
    #
    #  Discussion:
    #
    #    The Legendre polynomials are often defined on [-1,+1], while the
    #    Bernstein polynomials are defined on [0,1].  For this function,
    #    the Legendre polynomials have been shifted to share the [0,1]
    #    interval of definition.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    09 March 2016
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the maximum degree of the polynomials.
    #
    #    Output, real A(N+1,N+1), the Bernstein-to-Legendre matrix.
    #
    import numpy as np
    from r8_choose import r8_choose
    from r8_mop import r8_mop

    a = np.zeros([n + 1, n + 1])

    for i in range(0, n + 1):
        for j in range(0, n + 1):
            for k in range(0, i + 1):
                a[i,j] = a[i,j] \
                  + r8_mop ( i + k ) * r8_choose ( i, k ) ** 2 \
                  / r8_choose ( n + i, j + k )
            a[i,j] = a[i,j] * r8_choose ( n, j ) \
              * ( 2 * i + 1 ) / ( n + i + 1 )

    return a
def truncated_normal_a_moment ( order, mu, sigma, a ):

#*****************************************************************************80
#
## TRUNCATED_NORMAL_A_MOMENT: moments of the truncated Normal distribution.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    09 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    Phoebus Dhrymes,
#    Moments of Truncated Normal Distributions,
#    May 2005.
#
#  Parameters:
#
#    Input, integer ORDER, the order of the moment.
#    0 <= ORDER.
#
#    Input, real MU, SIGMA, the mean and standard deviation of the
#    parent Normal distribution.
#    0 < S.
#
#    Input, real A, the lower truncation limit.
#
#    Output, real VALUE, the moment of the PDF.
#
  from r8_mop import r8_mop
  from truncated_normal_b_moment import truncated_normal_b_moment

  value = r8_mop ( order ) \
    * truncated_normal_b_moment ( order, -mu, sigma, -a );

  return value
def truncated_normal_a_moment(order, mu, sigma, a):

    #*****************************************************************************80
    #
    ## TRUNCATED_NORMAL_A_MOMENT: moments of the truncated Normal distribution.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    09 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    Phoebus Dhrymes,
    #    Moments of Truncated Normal Distributions,
    #    May 2005.
    #
    #  Parameters:
    #
    #    Input, integer ORDER, the order of the moment.
    #    0 <= ORDER.
    #
    #    Input, real MU, SIGMA, the mean and standard deviation of the
    #    parent Normal distribution.
    #    0 < S.
    #
    #    Input, real A, the lower truncation limit.
    #
    #    Output, real VALUE, the moment of the PDF.
    #
    from r8_mop import r8_mop
    from truncated_normal_b_moment import truncated_normal_b_moment

    value = r8_mop ( order ) \
      * truncated_normal_b_moment ( order, -mu, sigma, -a )

    return value
Example #24
0
def oto_eigen_right(n):

    #*****************************************************************************80
    #
    ## OTO_EIGEN_RIGHT returns the right eigenvectors of the OTO matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    19 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of A.
    #
    #    Output, real A(N,N), the right eigenvector matrix.
    #
    import numpy as np
    from r8_mop import r8_mop

    a = np.zeros((n, n))

    for i in range(0, n):
        for j in range(0, n):
            angle = float((i + 1) * (j + 1)) * np.pi / float(n + 1)
            a[i,
              j] = r8_mop(i + j) * np.sqrt(2.0 / float(n + 1)) * np.sin(angle)

    return a
Example #25
0
def cheby_van2_determinant ( n ):

#*****************************************************************************80
#
## CHEBY_VAN2_DETERMINANT computes the determinant of the CHEBY_VAN2 matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    22 December 2014
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real DETERM, the determinant.
#
  from r8_mop import r8_mop
  from math import floor
  from math import sqrt

  if ( n <= 0 ):
    determ = 0.0
  elif ( n == 1 ):
    determ = 1.0
  else:
    determ = r8_mop ( floor ( n / 2 ) ) * sqrt ( 2.0 ) ** ( 4 - n )

  return determ
Example #26
0
def cheby_van2_determinant(n):

    #*****************************************************************************80
    #
    ## CHEBY_VAN2_DETERMINANT computes the determinant of the CHEBY_VAN2 matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    22 December 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real DETERM, the determinant.
    #
    from r8_mop import r8_mop
    from math import floor
    from math import sqrt

    if (n <= 0):
        determ = 0.0
    elif (n == 1):
        determ = 1.0
    else:
        determ = r8_mop(floor(n / 2)) * sqrt(2.0)**(4 - n)

    return determ
Example #27
0
def pascal1_inverse ( n ):

#*****************************************************************************80
#
## PASCAL1_INVERSE returns the inverse of the PASCAL1 matrix.
#
#  Formula:
#
#    if ( J = 1 )
#      A(I,J) = (-1)^(I+J)
#    elseif ( I = 1 )
#      A(I,J) = 0
#    else
#      A(I,J) = A(I-1,J) - A(I,J-1)
#
#  Example:
#
#    N = 5
#
#     1  0  0  0  0
#    -1  1  0  0  0
#     1 -2  1  0  0
#    -1  3 -3  1  0
#     1 -4  6 -4  1
#
#  Properties:
#
#    A is nonsingular.
#
#    A is lower triangular.
#
#    A is integral, therefore det ( A ) is integral, and 
#    det ( A ) * inverse ( A ) is integral.
#
#    det ( A ) = 1.
#
#    A is unimodular.
#
#    LAMBDA(1:N) = 1.
#
#    (0, 0, ..., 0, 1) is an eigenvector.
#
#    The inverse of A is the same as A, except that entries in "odd"
#    positions have changed sign:
#
#      B(I,J) = (-1)^(I+J) * A(I,J)
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    18 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):

      if ( j == 0 ):
        a[i,j] = r8_mop ( i + j )
      elif ( 0 < i ):
        a[i,j] = a[i-1,j-1] - a[i-1,j]

  return a
Example #28
0
def triv_inverse ( n, x, y, z ):

#*****************************************************************************80
#
## TRIV_INVERSE returns the inverse of the TRIV matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    28 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    CM daFonseca, J Petronilho,
#    Explicit Inverses of Some Tridiagonal Matrices,
#    Linear Algebra and Its Applications,
#    Volume 325, 2001, pages 7-21.
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Input, real X(N-1), Y(N), Z(N-1), the vectors that define
#    the subdiagonal, diagonal, and superdiagonal of A.
#    No entry of Y can be zero.
#
#    Output, real A(N,N), the inverse of the matrix.
#
  import numpy as np
  from r8_mop import r8_mop
  from sys import exit

  for i in range ( 0, n ):
    if ( y[i] == 0 ):
      print ''
      print 'TRIV_INVERSE - Fatal error!'
      print '  No entry of Y can be zero!'
      exit ( 'TRIV_INVERSE - Fatal error!' )

  d = np.zeros ( n )
  d[n-1] = y[n-1]
  for i in range ( n - 2, -1, -1 ):
    d[i] = y[i] - x[i] * z[i] / d[i+1]

  e = np.zeros ( n )
  e[0] = y[0]
  for i in range ( 1, n ):
    e[i] = y[i] - x[i-1] * z[i-1] / e[i-1]

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, i + 1 ):
      p1 = 1.0
      for k in range ( j, i ):
        p1 = p1 * x[k]
      p2 = 1.0
      for k in range ( i + 1, n ):
        p2 = p2 * d[k]
      p3 = 1.0
      for k in range ( j, n ):
        p3 = p3 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 * p2 / p3;

    for j in range ( i + 1, n ):
      p1 = 1.0
      for k in range ( i, j ):
        p1 = p1 * z[k]
      p2 = 1.0
      for k in range ( j + 1, n ):
        p2 = p2 * d[k]
      p3 = 1.0
      for k in range ( i, n ):
        p3 = p3 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 * p2 / p3

  return a
Example #29
0
def fibonacci3_inverse(n):

    #*****************************************************************************80
    #
    ## FIBONACCI3_INVERSE returns the inverse of the FIBONACCI3 matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    26 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    CM daFonseca, J Petronilho,
    #    Explicit Inverses of Some Tridiagonal Matrices,
    #    Linear Algebra and Its Applications,
    #    Volume 325, 2001, pages 7-21.
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real A(N,N), the inverse of the matrix.
    #
    import numpy as np
    from r8_mop import r8_mop

    a = np.zeros((n, n))

    d = np.zeros(n)

    d[n - 1] = 1.0
    for i in range(n - 2, -1, -1):
        d[i] = 1.0 + 1.0 / d[i + 1]

    for i in range(0, n):
        for j in range(0, i + 1):

            p1 = 1.0
            for k in range(i + 1, n):
                p1 = p1 * d[k]
            p2 = 1.0
            for k in range(0, n - j):
                p2 = p2 * d[k]
            a[i, j] = r8_mop(i + j) * p1 / p2

        for j in range(i + 1, n):
            p1 = 1.0
            for k in range(j + 1, n):
                p1 = p1 * d[k]
            p2 = 1.0
            for k in range(0, n - i):
                p2 = p2 * d[k]
            a[i, j] = p1 / p2

    return a
Example #30
0
def spline_inverse(n, x):

    #*****************************************************************************80
    #
    ## SPLINE_INVERSE returns the inverse of the SPLINE matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    28 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    CM daFonseca, J Petronilho,
    #    Explicit Inverses of Some Tridiagonal Matrices,
    #    Linear Algebra and Its Applications,
    #    Volume 325, 2001, pages 7-21.
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Input, real X(N-1), the parameters.
    #
    #    Output, real A(N,N), the inverse of the matrix.
    #
    import numpy as np
    from r8_mop import r8_mop

    d = np.zeros(n)
    d[n - 1] = 2.0 * x[n - 2]
    for i in range(n - 2, 0, -1):
        d[i] = 2.0 * (x[i - 1] + x[i]) - x[i] * x[i] / d[i + 1]
    d[0] = 2.0 * x[0] - x[0] * x[0] / d[1]

    e = np.zeros(n)
    e[0] = 2.0 * x[0]
    for i in range(1, n - 1):
        e[i] = 2.0 * (x[i - 1] + x[i]) - x[i - 1] * x[i - 1] / e[i - 1]
    e[n - 1] = 2.0 * x[n - 2] - x[n - 2] * x[n - 2] / e[n - 2]

    a = np.zeros((n, n))

    for i in range(0, n):

        for j in range(0, i + 1):
            p1 = 1.0
            for k in range(j, i):
                p1 = p1 * x[k]
            p2 = 1.0
            for k in range(i + 1, n):
                p2 = p2 * d[k]
            p3 = 1.0
            for k in range(j, n):
                p3 = p3 * e[k]
            a[i, j] = r8_mop(i + j) * p1 * p2 / p3

        for j in range(i + 1, n):
            p1 = 1.0
            for k in range(i, j):
                p1 = p1 * x[k]
            p2 = 1.0
            for k in range(j + 1, n):
                p2 = p2 * d[k]
            p3 = 1.0
            for k in range(i, n):
                p3 = p3 * e[k]
            a[i, j] = r8_mop(i + j) * p1 * p2 / p3

    return a
Example #31
0
def pascal2_inverse ( n ):

#*****************************************************************************80
#
## PASCAL2_INVERSE returns the inverse of the PASCAL2 matrix.
#
#  Formula:
#
#    A(I,J) = sum ( max(I,J) <= K <= N )
#      (-1)^(J+I) * COMB(K-1,I-1) * COMB(K-1,J-1)
#
#  Example:
#
#    N = 5
#
#      5 -10  10  -5   1
#    -10  30 -35  19  -4
#     10 -35  46 -27   6
#     -5  19 -27  17  -4
#      1  -4   6  -4   1
#
#  Properties:
#
#    A is symmetric: A' = A.
#
#    Because A is symmetric, it is normal.
#
#    Because A is normal, it is diagonalizable.
#
#    A is integral, therefore det ( A ) is integral, and 
#    det ( A ) * inverse ( A ) is integral.
#
#    The first row sums to 1, the others to 0.
#
#    The first column sums to 1, the others to 0.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    16 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of A.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from r8_choose import r8_choose
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, n ):
      klo = max ( i + 1, j + 1 )
      for k in range ( klo, n + 1 ):
        a[i,j] = a[i,j] + r8_mop ( i + j ) * r8_choose ( k - 1, i ) \
          * r8_choose ( k - 1, j )

  return a
Example #32
0
def cardinal_cos(j, m, n, t):

    #*****************************************************************************80
    #
    ## CARDINAL_COS evaluates the J-th cardinal cosine basis function.
    #
    #  Discussion:
    #
    #    The base points are T(I) = pi * I / ( M + 1 ), 0 <= I <= M + 1.
    #    Basis function J is 1 at T(J), and 0 at T(I) for I /= J
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    11 January 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    John Boyd,
    #    Exponentially convergent Fourier-Chebyshev quadrature schemes on
    #    bounded and infinite intervals,
    #    Journal of Scientific Computing,
    #    Volume 2, Number 2, 1987, pages 99-109.
    #
    #  Parameters:
    #
    #    Input, integer J, the index of the basis function.
    #    0 <= J <= M + 1.
    #
    #    Input, integer M, indicates the size of the basis set.
    #
    #    Input, integer N, the number of sample points.
    #
    #    Input, real T(N), one or more points in [0,pi] where the
    #    basis function is to be evaluated.
    #
    #    Output, real C(N), the value of the function at T.
    #
    import numpy as np
    from r8_mop import r8_mop
    from math import cos
    from math import sin

    r8_epsilon = 2.220446049250313E-16
    r8_pi = 3.141592653589793

    if ((j % (m + 1)) == 0):
        cj = 2.0
    else:
        cj = 1.0

    tj = r8_pi * j / (m + 1)

    c = np.zeros(n)

    for i in range(0, n):
        if (abs(t[i] - tj) < 5.0 * r8_epsilon):
            c[i] = 1.0
        else:
            c[i] = r8_mop ( ( j + 1 ) % 2 ) * sin ( t[i] ) * sin ( ( m + 1 ) * t[i] ) \
              / cj / ( m + 1 ) / ( cos ( t[i] ) - cos ( tj ) )

    return c
Example #33
0
def chow_inverse ( alpha, beta, n ):

#*****************************************************************************80
#
#%\# CHOW_INVERSE returns the inverse of the Chow matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    24 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, real ALPHA, the ALPHA value.  A typical value is 1.0.
#
#    Input, real BETA, the BETA value.  A typical value is 0.0.
#
#    Input, integer N, the order of A.
#
#    Output, real A(N,N), the matrix.
#
  import numpy as np
  from r8_mop import r8_mop
  from sys import exit

  a = np.zeros ( ( n, n ) )

  if ( 0.0 == alpha and beta == 0.0 ):

    print ''
    print 'CHOW_INVERSE - Fatal error!'
    print '  The Chow matrix is not invertible, because'
    print '  ALPHA = 0 and BETA = 0.'
    exit ( 'CHOW_INVERSE - Fatal error!' )

  elif ( 0.0 == alpha and beta != 0.0 ):

    for i in range ( 0, n ):
      for j in range ( 0, n ):

        if ( i <= j ):
          a[i,j] = r8_mop ( j - i ) / beta ** ( j + 1 - i )

  elif ( 0.0 != alpha and beta == 0.0 ):

    if ( 1 < n ):
      print ''
      print 'CHOW_INVERSE - Fatal error!'
      print '  The Chow matrix is not invertible, because'
      print '  BETA = 0 and 1 < N.'
      exit ( 'CHOW_INVERSE - Fatal error!' )

    a[0.0] = 1.0 / alpha

  else:

    d = np.zeros ( n + 1 )

    d[0] = 1.0
    d[1] = beta
    for i in range ( 2, n + 1 ):
      d[i] = beta * d[i-1] + alpha * beta * d[i-2]

    dp = np.zeros ( n + 2 )
    dp[0] = 1.0 / beta
    dp[1] = 1.0
    dp[2] = alpha + beta
    for i in range ( 2, n + 1 ):
      dp[i+1] = d[i] + alpha * d[i-1]

    for i in range ( 0, n ):
      for j in range ( 0, i ):
        a[i,j] = - alpha * ( alpha * beta ) ** ( i - j ) * dp[j] * d[n-1-i] \
          / dp[n+1]

      for j in range ( i, n ):
        a[i,j] = r8_mop ( i + j ) * dp[i+1] * d[n-j] / ( beta * dp[n+1] )

  return a
Example #34
0
def spline_inverse ( n, x ):

#*****************************************************************************80
#
## SPLINE_INVERSE returns the inverse of the SPLINE matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    28 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    CM daFonseca, J Petronilho,
#    Explicit Inverses of Some Tridiagonal Matrices,
#    Linear Algebra and Its Applications,
#    Volume 325, 2001, pages 7-21.
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Input, real X(N-1), the parameters.
#
#    Output, real A(N,N), the inverse of the matrix.
#
  import numpy as np
  from r8_mop import r8_mop

  d = np.zeros ( n )
  d[n-1] = 2.0 * x[n-2]
  for i in range ( n - 2, 0, -1 ):
    d[i] = 2.0 * ( x[i-1] + x[i] ) - x[i] * x[i] / d[i+1]
  d[0] = 2.0 * x[0] - x[0] * x[0] / d[1]

  e = np.zeros ( n )
  e[0] = 2.0 * x[0]
  for i in range ( 1, n - 1 ):
    e[i] = 2.0 * ( x[i-1] + x[i] ) - x[i-1] * x[i-1] / e[i-1]
  e[n-1] = 2.0 * x[n-2] - x[n-2] * x[n-2] / e[n-2]

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):

    for j in range ( 0, i + 1 ):
      p1 = 1.0
      for k in range ( j, i ):
        p1 = p1 * x[k]
      p2 = 1.0
      for k in range ( i + 1, n ):
        p2 = p2 * d[k]
      p3 = 1.0
      for k in range ( j, n ):
        p3 = p3 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 * p2 / p3

    for j in range ( i + 1, n ):
      p1 = 1.0
      for k in range ( i, j ):
        p1 = p1 * x[k]
      p2 = 1.0
      for k in range ( j + 1, n ):
        p2 = p2 * d[k]
      p3 = 1.0
      for k in range ( i, n ):
        p3 = p3 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 * p2 / p3

  return a
Example #35
0
def dorr_inverse ( alpha, n ):

#*****************************************************************************80
#
## DORR_INVERSE returns the inverse of the DORR matrix.
#
#  Discussion:
#
#    The DORR matrix is a special case of the TRIV matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    CM daFonseca, J Petronilho,
#    Explicit Inverses of Some Tridiagonal Matrices,
#    Linear Algebra and Its Applications,
#    Volume 325, 2001, pages 7-21.
#
#  Parameters:
#
#    Input, real ALPHA, the parameter.
#
#    Input, integer N, the order of the matrix.
#
#    Output, real A(N,N), the inverse of the matrix.
#
  import numpy as np
  from r8_mop import r8_mop
#
#  Form the three diagonals.
#
  x = np.zeros ( n - 1 )
  y = np.zeros ( n )
  z = np.zeros ( n - 1 )

  np1 = float ( n + 1 )

  for i in range ( 0, n ):
    for j in range ( 0, n ):

      if ( i + 1 <= ( ( n + 1 ) // 2 ) ):

        if ( j == i - 1 ):
          x[i-1] = - alpha * np1 ** 2
        elif ( j == i ):
          y[i] = 2.0 * alpha * np1 ** 2 + 0.5 * np1 - float ( i + 1 )
        elif ( j == i + 1 ):
          z[i] = - alpha * np1 ** 2 - 0.5 * np1 + float ( i + 1 )

      else:

        if ( j == i - 1 ):
          x[i-1] = - alpha * np1 ** 2 + 0.5 * np1 - float ( i + 1 )
        elif ( j == i ):
          y[i] = 2.0 * alpha * np1 ** 2 - 0.5 * np1 + float ( i + 1 )
        elif ( j == i + 1 ):
          z[i] = - alpha * np1 ** 2
#
#  Now evaluate the inverse.
#
  a = np.zeros ( ( n, n ) )

  d = np.zeros ( n )
  e = np.zeros ( n )

  d[n-1] = y[n-1]
  for i in range ( n - 2, -1, -1 ):
    d[i] = y[i] - x[i] * z[i] / d[i+1]

  e[0] = y[0]
  for i in range ( 1, n ):
    e[i] = y[i] - x[i-1] * z[i-1] / e[i-1]

  for i in range ( 0, n ):

    for j in range ( 0, i + 1 ):

      p1 = 1.0
      for k in range ( j, i ):
        p1 = p1 * x[k]
      p2 = 1.0
      for k in range ( i + 1, n ):
        p2 = p2 * d[k]
      p3 = 1.0
      for k in range ( j, n ):
        p3 = p3 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 * p2 / p3

    for j in range ( i + 1, n ):

      p1 = 1.0
      for k in range ( i, j ):
        p1 = p1 * z[k]
      p2 = 1.0
      for k in range ( j + 1, n ):
        p2 = p2 * d[k]
      p3 = 1.0
      for k in range ( i, n ):
        p3 = p3 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 * p2 / p3

  return a
Example #36
0
def tris_inverse(n, alpha, beta, gam):

    #*****************************************************************************80
    #
    ## TRIS_INVERSE returns the inverse of the TRIS matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    28 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    CM daFonseca, J Petronilho,
    #    Explicit Inverses of Some Tridiagonal Matrices,
    #    Linear Algebra and Its Applications,
    #    Volume 325, 2001, pages 7-21.
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Input, real ALPHA, BETA, GAM, the constant values associated with the
    #    subdiagonal, diagonal and superdiagonal of the matrix.
    #
    #    Output, real A(N,N), the inverse of the matrix.
    #
    import numpy as np
    from r8_mop import r8_mop

    d = np.zeros(n)
    d[n - 1] = beta
    for i in range(n - 2, -1, -1):
        d[i] = beta - alpha * gam / d[i + 1]

    a = np.zeros((n, n))

    for i in range(0, n):
        for j in range(0, i + 1):
            p1 = 1.0
            for k in range(i + 1, n):
                p1 = p1 * d[k]
            p2 = 1.0
            for k in range(0, n - j):
                p2 = p2 * d[k]
            a[i, j] = r8_mop(i + j) * alpha**(i - j) * p1 / p2
        for j in range(i + 1, n):
            p1 = 1.0
            for k in range(j + 1, n):
                p1 = p1 * d[k]
            p2 = 1.0
            for k in range(0, n - i):
                p2 = p2 * d[k]
            a[i, j] = r8_mop(i + j) * gam**(j - i) * p1 / p2

    return a
def cardinal_sin(j, m, n, t):

    # *****************************************************************************80
    #
    ## CARDINAL_SIN evaluates the J-th cardinal sine basis function.
    #
    #  Discussion:
    #
    #    The base points are T(I) = pi * I / ( M + 1 ), 0 <= I <= M + 1.
    #    Basis function J is 1 at T(J), and 0 at T(I) for I /= J
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    16 January 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    John Boyd,
    #    Exponentially convergent Fourier-Chebyshev quadrature schemes on
    #    bounded and infinite intervals,
    #    Journal of Scientific Computing,
    #    Volume 2, Number 2, 1987, pages 99-109.
    #
    #  Parameters:
    #
    #    Input, integer J, the index of the basis function.
    #    0 <= J <= M + 1.
    #
    #    Input, integer M, indicates the size of the basis set.
    #
    #    Input, integer N, the number of evaluation points.
    #
    #    Input, real T(N), one or more points in [0,pi] where the
    #    basis function is to be evaluated.
    #
    #    Output, real S(N), the value of the function at T.
    #
    import numpy as np
    from r8_mop import r8_mop
    from math import cos
    from math import sin

    r8_epsilon = 2.220446049250313e-16
    r8_pi = 3.141592653589793

    tj = r8_pi * j / (m + 1)

    s = np.zeros(n)

    for i in range(0, n):
        if abs(t[i] - tj) < 5.0 * r8_epsilon:
            s[i] = 1.0
        else:
            s[i] = r8_mop((j + 1) % 2) * sin(t[i]) * sin((m + 1) * t[i]) / (m + 1) / (cos(t[i]) - cos(tj))

    return s
Example #38
0
def fibonacci3_inverse ( n ):

#*****************************************************************************80
#
## FIBONACCI3_INVERSE returns the inverse of the FIBONACCI3 matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    26 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    CM daFonseca, J Petronilho,
#    Explicit Inverses of Some Tridiagonal Matrices,
#    Linear Algebra and Its Applications,
#    Volume 325, 2001, pages 7-21.
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real A(N,N), the inverse of the matrix.
#
  import numpy as np
  from r8_mop import r8_mop

  a = np.zeros ( ( n, n ) )

  d = np.zeros ( n )

  d[n-1] = 1.0
  for i in range ( n - 2, -1, -1 ):
    d[i] = 1.0 + 1.0 / d[i+1]

  for i in range ( 0, n ):
    for j in range ( 0, i + 1 ):

      p1 = 1.0
      for k in range ( i + 1, n ):
        p1 = p1 * d[k]
      p2 = 1.0
      for k in range ( 0, n - j ):
        p2 = p2 * d[k]
      a[i,j] = r8_mop ( i + j ) * p1 / p2

    for j in range ( i + 1, n ):
      p1 = 1.0
      for k in range ( j + 1, n ):
        p1 = p1 * d[k]
      p2 = 1.0
      for k in range ( 0, n - i ):
        p2 = p2 * d[k]
      a[i,j] = p1 / p2

  return a
Example #39
0
def triv_inverse(n, x, y, z):

    #*****************************************************************************80
    #
    ## TRIV_INVERSE returns the inverse of the TRIV matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    28 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    CM daFonseca, J Petronilho,
    #    Explicit Inverses of Some Tridiagonal Matrices,
    #    Linear Algebra and Its Applications,
    #    Volume 325, 2001, pages 7-21.
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Input, real X(N-1), Y(N), Z(N-1), the vectors that define
    #    the subdiagonal, diagonal, and superdiagonal of A.
    #    No entry of Y can be zero.
    #
    #    Output, real A(N,N), the inverse of the matrix.
    #
    import numpy as np
    from r8_mop import r8_mop
    from sys import exit

    for i in range(0, n):
        if (y[i] == 0):
            print ''
            print 'TRIV_INVERSE - Fatal error!'
            print '  No entry of Y can be zero!'
            exit('TRIV_INVERSE - Fatal error!')

    d = np.zeros(n)
    d[n - 1] = y[n - 1]
    for i in range(n - 2, -1, -1):
        d[i] = y[i] - x[i] * z[i] / d[i + 1]

    e = np.zeros(n)
    e[0] = y[0]
    for i in range(1, n):
        e[i] = y[i] - x[i - 1] * z[i - 1] / e[i - 1]

    a = np.zeros((n, n))

    for i in range(0, n):
        for j in range(0, i + 1):
            p1 = 1.0
            for k in range(j, i):
                p1 = p1 * x[k]
            p2 = 1.0
            for k in range(i + 1, n):
                p2 = p2 * d[k]
            p3 = 1.0
            for k in range(j, n):
                p3 = p3 * e[k]
            a[i, j] = r8_mop(i + j) * p1 * p2 / p3

        for j in range(i + 1, n):
            p1 = 1.0
            for k in range(i, j):
                p1 = p1 * z[k]
            p2 = 1.0
            for k in range(j + 1, n):
                p2 = p2 * d[k]
            p3 = 1.0
            for k in range(i, n):
                p3 = p3 * e[k]
            a[i, j] = r8_mop(i + j) * p1 * p2 / p3

    return a
Example #40
0
def wilk21_inverse ( n ):

#*****************************************************************************80
#
## WILK21_INVERSE returns the inverse of the WILK21 matrix.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    27 March 2015
#
#  Author:
#
#    John Burkardt
#
#  Reference:
#
#    CM daFonseca, J Petronilho,
#    Explicit Inverses of Some Tridiagonal Matrices,
#    Linear Algebra and Its Applications,
#    Volume 325, 2001, pages 7-21.
#
#  Parameters:
#
#    Input, integer N, the order of the matrix.
#
#    Output, real A(N,N), the inverse of the matrix.
#
  import numpy as np
  from r8_mop import r8_mop

  y = np.zeros ( n )
  for i in range ( 0, n ):
    y[i] = float ( abs ( i + 1 - ( n + 1 ) // 2 ) )

  d = np.zeros ( n )
  d[n-1] = y[n-1]
  for i in range ( n - 2, -1, -1 ):
    d[i] = y[i] - 1.0 / d[i+1]

  e = np.zeros ( n )
  e[0] = y[0]
  for i in range ( 1, n ):
    e[i] = y[i] - 1.0 / e[i-1]

  a = np.zeros ( ( n, n ) )

  for i in range ( 0, n ):
    for j in range ( 0, i + 1 ):
      p1 = 1.0
      for k in range ( i + 1, n ):
        p1 = p1 * d[k]
      p2 = 1.0
      for k in range ( j, n ):
        p2 = p2 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 / p2
    for j in range ( i + 1, n ):
      p1 = 1.0
      for k in range ( j + 1, n ):
        p1 = p1 * d[k]
      p2 = 1.0
      for k in range ( i, n ):
        p2 = p2 * e[k]
      a[i,j] = r8_mop ( i + j ) * p1 / p2

  return a
Example #41
0
def wilk21_inverse(n):

    #*****************************************************************************80
    #
    ## WILK21_INVERSE returns the inverse of the WILK21 matrix.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    27 March 2015
    #
    #  Author:
    #
    #    John Burkardt
    #
    #  Reference:
    #
    #    CM daFonseca, J Petronilho,
    #    Explicit Inverses of Some Tridiagonal Matrices,
    #    Linear Algebra and Its Applications,
    #    Volume 325, 2001, pages 7-21.
    #
    #  Parameters:
    #
    #    Input, integer N, the order of the matrix.
    #
    #    Output, real A(N,N), the inverse of the matrix.
    #
    import numpy as np
    from r8_mop import r8_mop

    y = np.zeros(n)
    for i in range(0, n):
        y[i] = float(abs(i + 1 - (n + 1) // 2))

    d = np.zeros(n)
    d[n - 1] = y[n - 1]
    for i in range(n - 2, -1, -1):
        d[i] = y[i] - 1.0 / d[i + 1]

    e = np.zeros(n)
    e[0] = y[0]
    for i in range(1, n):
        e[i] = y[i] - 1.0 / e[i - 1]

    a = np.zeros((n, n))

    for i in range(0, n):
        for j in range(0, i + 1):
            p1 = 1.0
            for k in range(i + 1, n):
                p1 = p1 * d[k]
            p2 = 1.0
            for k in range(j, n):
                p2 = p2 * e[k]
            a[i, j] = r8_mop(i + j) * p1 / p2
        for j in range(i + 1, n):
            p1 = 1.0
            for k in range(j + 1, n):
                p1 = p1 * d[k]
            p2 = 1.0
            for k in range(i, n):
                p2 = p2 * e[k]
            a[i, j] = r8_mop(i + j) * p1 / p2

    return a