예제 #1
0
def neumann(n):
    """
    neumann  Singular matrix from the discrete Neumann problem (sparse).
         neumann(n) is the singular, row diagonally dominant matrix resulting
         from discretizing the neumann problem with the usual five point
         operator on a regular mesh.
         It has a one-dimensional null space with null vector ones(n,1).
         the dimension n should be a perfect square, or else a 2-vector,
         in which case the dimension of the matrix is n[1]*n[2].

         Reference:
         R.J. Plemmons, Regular splittings and the discrete Neumann
         problem, Numer. Math., 25 (1976), pp. 153-161.
    """
    try:
        m, n = n.shape
    except AttributeError:
        m = int(np.sqrt(n))
        if m**2 != n:
            raise ValueError('N must be a perfect square.')
        n = m

    t = tridiag(m, -1, 2, -1).todense()
    t[0, 1] = -2
    t[m - 1, m - 2] = -2

    a = np.kron(t, np.eye(n)) + np.kron(np.eye(n), t)

    return a, t
예제 #2
0
def lesp(n):
    """
    LESP   A tridiagonal matrix with real, sensitive eigenvalues.
       LESP(N) is an N-by-N matrix whose eigenvalues are real and smoothly
       distributed in the interval approximately [-2*N-3.5, -4.5].
       The sensitivities of the eigenvalues increase exponentially as
       the eigenvalues grow more negative.
       The matrix is similar to the symmetric tridiagonal matrix with
       the same diagonal entries and with off-diagonal entries 1,
       via a similarity transformation with d = np.diag(1!,2!,...,N!).

       References:
       H.W.J. Lenferink and M.N. Spijker, On the use of stability regions in
            the numerical analysis of initial value problems,
            Math. Comp., 57 (1991), pp. 221-237.
       L.N. Trefethen, Pseudospectra of matrices, in Numerical Analysis 1991,
            Proceedings of the 14th Dundee Conference,
            D.F. Griffiths and G.A. Watson, eds, Pitman Research Notes in
            Mathematics, volume 260, Longman Scientific and Technical, Essex,
            UK, 1992, pp. 234-266.
    """
    x = np.arange(2., n + 1)
    y = -(2. * np.arange(2, n + 2) + 1)
    t = tridiag(1 / x, y, x).todense()

    return t
예제 #3
0
def poisson(n):
    """
    poisson   Block tridiagonal matrix from Poisson's equation (sparse).
          poisson(n) is the block tridiagonal matrix of order n**2
          resulting from discretizing Poisson's equation with the
          5-point operator on an n-by-n mesh.

          Reference:
          G.H. Golub and C.F. Van Loan, Matrix Computations, second edition,
          Johns Hopkins University Press, Baltimore, Maryland, 1989
          (Section 4.5.4).
    """
    s = tridiag(n, -1, 2, -1)
    i = sparse.eye(n, n)
    a = sparse.kron(i, s) + sparse.kron(s, i)

    return a
예제 #4
0
파일: neumann.py 프로젝트: macd/rogues
def neumann(n):
    """
    neumann  Singular matrix from the discrete Neumann problem (sparse).
         neumann(n) is the singular, row diagonally dominant matrix resulting
         from discretizing the neumann problem with the usual five point
         operator on a regular mesh.
         It has a one-dimensional null space with null vector ones(n,1).
         the dimension n should be a perfect square, or else a 2-vector,
         in which case the dimension of the matrix is n[1]*n[2].

         a, t = neumann(n) where a is the singular matrix of a*u = b
         which is the finite difference analog of the Neumann problem:

                                 del(u) = -f   in  R
                                 du/dn  =  g   on dR

         The matrix t corresponds to a specific ordering on a regular mesh
         of the finite differences where

                                a = t @ I + I @ t

         where I is the identity matrix and @ denotes the Kronecker product.
         The matrix t is tri-diagonal whose rows sum to zero.

         Reference:
         R.J. Plemmons, Regular splittings and the discrete Neumann
         problem, Numer. Math., 25 (1976), pp. 153-161.
    """
    try:
        m, n = n.shape
    except AttributeError:
        m = int(np.sqrt(n))
        if m**2 != n:
            raise ValueError('N must be a perfect square.')
        n = m

    t = tridiag(m, -1, 2, -1).todense()
    t[0, 1] = -2
    t[m - 1, m - 2] = -2

    a = np.kron(t, np.eye(n)) + np.kron(np.eye(n), t)

    return a, t