当前位置: 首页>>代码示例>>Python>>正文


Python linalg.solve_banded方法代码示例

本文整理汇总了Python中scipy.linalg.solve_banded方法的典型用法代码示例。如果您正苦于以下问题:Python linalg.solve_banded方法的具体用法?Python linalg.solve_banded怎么用?Python linalg.solve_banded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.linalg的用法示例。


在下文中一共展示了linalg.solve_banded方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _radau

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import solve_banded [as 别名]
def _radau(alpha, beta, xr):
    """From <http://www.scientificpython.net/pyblog/radau-quadrature>:
    Compute the Radau nodes and weights with the preassigned node xr.

    Based on the section 7 of the paper

        Some modified matrix eigenvalue problems,
        Gene Golub,
        SIAM Review Vol 15, No. 2, April 1973, pp.318--334.
    """
    from scipy.linalg import solve_banded

    n = len(alpha) - 1
    f = numpy.zeros(n)
    f[-1] = beta[-1]
    A = numpy.vstack((numpy.sqrt(beta), alpha - xr))
    J = numpy.vstack((A[:, 0:-1], A[0, 1:]))
    delta = solve_banded((1, 1), J, f)
    alphar = alpha.copy()
    alphar[-1] = xr + delta[-1]
    x, w = scheme_from_rc(alphar, beta, mode="numpy")
    return x, w 
开发者ID:nschloe,项目名称:quadpy,代码行数:24,代码来源:_gauss_radau.py

示例2: _get_natural_f

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import solve_banded [as 别名]
def _get_natural_f(knots):
    """Returns mapping of natural cubic spline values to 2nd derivatives.

    .. note:: See 'Generalized Additive Models', Simon N. Wood, 2006, pp 145-146

    :param knots: The 1-d array knots used for cubic spline parametrization,
     must be sorted in ascending order.
    :return: A 2-d array mapping natural cubic spline values at
     knots to second derivatives.

    :raise ImportError: if scipy is not found, required for
     ``linalg.solve_banded()``
    """
    try:
        from scipy import linalg
    except ImportError: # pragma: no cover
        raise ImportError("Cubic spline functionality requires scipy.")

    h = knots[1:] - knots[:-1]
    diag = (h[:-1] + h[1:]) / 3.
    ul_diag = h[1:-1] / 6.
    banded_b = np.array([np.r_[0., ul_diag], diag, np.r_[ul_diag, 0.]])
    d = np.zeros((knots.size - 2, knots.size))
    for i in range(knots.size - 2):
        d[i, i] = 1. / h[i]
        d[i, i + 2] = 1. / h[i + 1]
        d[i, i + 1] = - d[i, i] - d[i, i + 2]

    fm = linalg.solve_banded((1, 1), banded_b, d)

    return np.vstack([np.zeros(knots.size), fm, np.zeros(knots.size)])


# Cyclic Cubic Regression Splines 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:36,代码来源:mgcv_cubic_splines.py

示例3: __interpolateSpline__

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import solve_banded [as 别名]
def __interpolateSpline__(self):
        """Calculate natural spline coefficients that fit the data exactly."""
        # Get x and y values for all supplied points
        x = self.source[:, 0]
        y = self.source[:, 1]
        mdim = len(x)
        h = [x[i + 1] - x[i] for i in range(0, mdim - 1)]
        # Initialize the matrix
        Ab = np.zeros((3, mdim))
        # Construct the Ab banded matrix and B vector
        Ab[1, 0] = 1  # A[0, 0] = 1
        B = [0]
        for i in range(1, mdim - 1):
            Ab[2, i - 1] = h[i - 1]  # A[i, i - 1] = h[i - 1]
            Ab[1, i] = 2 * (h[i] + h[i - 1])  # A[i, i] = 2*(h[i] + h[i - 1])
            Ab[0, i + 1] = h[i]  # A[i, i + 1] = h[i]
            B.append(3 * ((y[i + 1] - y[i]) / (h[i]) - (y[i] - y[i - 1]) / (h[i - 1])))
        Ab[1, mdim - 1] = 1  # A[-1, -1] = 1
        B.append(0)
        # Solve the system for c coefficients
        c = linalg.solve_banded((1, 1), Ab, B, True, True)
        # Calculate other coefficients
        b = [
            ((y[i + 1] - y[i]) / h[i] - h[i] * (2 * c[i] + c[i + 1]) / 3)
            for i in range(0, mdim - 1)
        ]
        d = [(c[i + 1] - c[i]) / (3 * h[i]) for i in range(0, mdim - 1)]
        # Store coefficients
        self.__splineCoefficients__ = np.array([y[0:-1], b, c[0:-1], d]) 
开发者ID:giovaniceotto,项目名称:RocketPy,代码行数:31,代码来源:Function.py

示例4: _lobatto

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import solve_banded [as 别名]
def _lobatto(alpha, beta, xl1, xl2):
    """Compute the Lobatto nodes and weights with the preassigned node xl1, xl2.
    Based on the section 7 of the paper

        Some modified matrix eigenvalue problems,
        Gene Golub,
        SIAM Review Vol 15, No. 2, April 1973, pp.318--334,

    and

        http://www.scientificpython.net/pyblog/radau-quadrature
    """
    from scipy.linalg import solve_banded, solve

    n = len(alpha) - 1
    en = numpy.zeros(n)
    en[-1] = 1
    A1 = numpy.vstack((numpy.sqrt(beta), alpha - xl1))
    J1 = numpy.vstack((A1[:, 0:-1], A1[0, 1:]))
    A2 = numpy.vstack((numpy.sqrt(beta), alpha - xl2))
    J2 = numpy.vstack((A2[:, 0:-1], A2[0, 1:]))
    g1 = solve_banded((1, 1), J1, en)
    g2 = solve_banded((1, 1), J2, en)
    C = numpy.array(((1, -g1[-1]), (1, -g2[-1])))
    xl = numpy.array((xl1, xl2))
    ab = solve(C, xl)

    alphal = alpha
    alphal[-1] = ab[0]
    betal = beta
    betal[-1] = ab[1]
    x, w = scheme_from_rc(alphal, betal, mode="numpy")
    return x, w 
开发者ID:nschloe,项目名称:quadpy,代码行数:35,代码来源:_gauss_lobatto.py

示例5: SolveBanded

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import solve_banded [as 别名]
def SolveBanded(A, D, bw=3):
    # Find the diagonals
    ud = np.insert(np.diag(A,1), 0, 0) # upper diagonal
    d = np.diag(A) # main diagonal
    ld = np.insert(np.diag(A,-1), len(d)-1, 0) # lower diagonal
    # simplified matrix
    ab = np.matrix([
        ud,
        d,
        ld,
    ])
    #ds9(ab)
    return solve_banded((1, 1), ab, D ) 
开发者ID:mzechmeister,项目名称:serval,代码行数:15,代码来源:cspline.py

示例6: __init__

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import solve_banded [as 别名]
def __init__(self, x, y):
        x = np.asarray(x, dtype=float)
        y = np.asarray(y, dtype=float)

        n = x.shape[0]
        dx = np.diff(x)
        dy = np.diff(y, axis=0)
        dxr = dx.reshape([dx.shape[0]] + [1] * (y.ndim - 1))

        c = np.empty((3, n - 1) + y.shape[1:])
        if n > 2:
            A = np.ones((2, n))
            b = np.empty((n,) + y.shape[1:])
            b[0] = 0
            b[1:] = 2 * dy / dxr
            s = solve_banded((1, 0), A, b, overwrite_ab=True, overwrite_b=True,
                             check_finite=False)
            c[0] = np.diff(s, axis=0) / (2 * dxr)
            c[1] = s[:-1]
            c[2] = y[:-1]
        else:
            c[0] = 0
            c[1] = dy / dxr
            c[2] = y[:-1]

        super(_QuadraticSpline, self).__init__(c, x) 
开发者ID:nmayorov,项目名称:pyins,代码行数:28,代码来源:sim.py

示例7: _lobatto

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import solve_banded [as 别名]
def _lobatto(coefficients, preassigned):
    """
    Compute the Lobatto nodes and weights with the preassigned value pair.
    Based on the section 7 of the paper

        Some modified matrix eigenvalue problems,
        Gene Golub,
        SIAM Review Vol 15, No. 2, April 1973, pp.318--334,

    and

        http://www.scientificpython.net/pyblog/radau-quadrature

    Args:
        coefficients (numpy.ndarray):
            Three terms recurrence coefficients.
        preassigned (Tuple[float, float]):
            Values that are assume to be fixed.
    """
    alpha = numpy.array(coefficients[0])
    beta = numpy.array(coefficients[1])
    vec_en = numpy.zeros(len(alpha)-1)
    vec_en[-1] = 1
    mat_a1 = numpy.vstack((numpy.sqrt(beta), alpha-preassigned[0]))
    mat_j1 = numpy.vstack((mat_a1[:, 0:-1], mat_a1[0, 1:]))
    mat_a2 = numpy.vstack((numpy.sqrt(beta), alpha - preassigned[1]))
    mat_j2 = numpy.vstack((mat_a2[:, 0:-1], mat_a2[0, 1:]))
    mat_g1 = solve_banded((1, 1), mat_j1, vec_en)
    mat_g2 = solve_banded((1, 1), mat_j2, vec_en)
    mat_c = numpy.array(((1, -mat_g1[-1]), (1, -mat_g2[-1])))
    alpha[-1], beta[-1] = solve(mat_c, preassigned)

    return numpy.array([alpha, beta]) 
开发者ID:jonathf,项目名称:chaospy,代码行数:35,代码来源:gauss_lobatto.py


注:本文中的scipy.linalg.solve_banded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。