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


Python linalg.companion函数代码示例

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


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

示例1: test_basic

    def test_basic(self):
        c = companion([1, 2, 3])
        expected = array([[-2.0, -3.0], [1.0, 0.0]])
        assert_array_equal(c, expected)

        c = companion([2.0, 5.0, -10.0])
        expected = array([[-2.5, 5.0], [1.0, 0.0]])
        assert_array_equal(c, expected)
开发者ID:person142,项目名称:scipy,代码行数:8,代码来源:test_special_matrices.py

示例2: test_fiedler_companion

def test_fiedler_companion():
    fc = fiedler_companion([])
    assert_equal(fc.size, 0)
    fc = fiedler_companion([1.])
    assert_equal(fc.size, 0)
    fc = fiedler_companion([1., 2.])
    assert_array_equal(fc, np.array([[-2.]]))
    fc = fiedler_companion([1e-12, 2., 3.])
    assert_array_almost_equal(fc, companion([1e-12, 2., 3.]))
    with assert_raises(ValueError):
        fiedler_companion([0, 1, 2])
    fc = fiedler_companion([1., -16., 86., -176., 105.])
    assert_array_almost_equal(eigvals(fc),
                              np.array([7., 5., 3., 1.]))
开发者ID:WarrenWeckesser,项目名称:scipy,代码行数:14,代码来源:test_special_matrices.py

示例3: test_from_state_space

 def test_from_state_space(self):
     # Ensure that freqresp works with a system that was created from the
     # state space representation matrices A, B, C, D.  In this case,
     # system.num will be a 2-D array with shape (1, n+1), where (n,n) is
     # the shape of A.
     # A Butterworth lowpass filter is used, so we know the exact
     # frequency response.
     a = np.array([1.0, 2.0, 2.0, 1.0])
     A = linalg.companion(a).T
     B = np.array([[0.0],[0.0],[1.0]])
     C = np.array([[1.0, 0.0, 0.0]])
     D = np.array([[0.0]])
     with warnings.catch_warnings():
         warnings.simplefilter("ignore", BadCoefficients)
         system = lti(A, B, C, D)
         w, H = freqresp(system, n=100)
     expected_magnitude = np.sqrt(1.0 / (1.0 + w**6))
     assert_almost_equal(np.abs(H), expected_magnitude)
开发者ID:7924102,项目名称:scipy,代码行数:18,代码来源:test_ltisys.py

示例4: test_from_state_space

    def test_from_state_space(self):
        # Ensure that bode works with a system that was created from the
        # state space representation matrices A, B, C, D.  In this case,
        # system.num will be a 2-D array with shape (1, n+1), where (n,n)
        # is the shape of A.
        # A Butterworth lowpass filter is used, so we know the exact
        # frequency response.
        a = np.array([1.0, 2.0, 2.0, 1.0])
        A = linalg.companion(a).T
        B = np.array([[0.0], [0.0], [1.0]])
        C = np.array([[1.0, 0.0, 0.0]])
        D = np.array([[0.0]])
        with suppress_warnings() as sup:
            sup.filter(BadCoefficients)
            system = lti(A, B, C, D)
            w, mag, phase = bode(system, n=100)

        expected_magnitude = 20 * np.log10(np.sqrt(1.0 / (1.0 + w**6)))
        assert_almost_equal(mag, expected_magnitude)
开发者ID:BranYang,项目名称:scipy,代码行数:19,代码来源:test_ltisys.py

示例5: time_companion

 def time_companion(self, size):
     sl.companion(self.x)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:2,代码来源:linalg.py

示例6: lfilter_zi

def lfilter_zi(b, a):
    """
    Compute an initial state `zi` for the lfilter function that corresponds
    to the steady state of the step response.

    A typical use of this function is to set the initial state so that the
    output of the filter starts at the same value as the first element of
    the signal to be filtered.

    Parameters
    ----------
    b, a : array_like (1-D)
        The IIR filter coefficients. See `scipy.signal.lfilter` for more
        information.

    Returns
    -------
    zi : 1-D ndarray
        The initial state for the filter.

    Notes
    -----
    A linear filter with order m has a state space representation (A, B, C, D),
    for which the output y of the filter can be expressed as::

        z(n+1) = A*z(n) + B*x(n)
        y(n)   = C*z(n) + D*x(n)

    where z(n) is a vector of length m, A has shape (m, m), B has shape
    (m, 1), C has shape (1, m) and D has shape (1, 1) (assuming x(n) is
    a scalar).  lfilter_zi solves::

        zi = A*zi + B

    In other words, it finds the initial condition for which the response
    to an input of all ones is a constant.

    Given the filter coefficients `a` and `b`, the state space matrices
    for the transposed direct form II implementation of the linear filter,
    which is the implementation used by scipy.signal.lfilter, are::

        A = scipy.linalg.companion(a).T
        B = b[1:] - a[1:]*b[0]

    assuming `a[0]` is 1.0; if `a[0]` is not 1, `a` and `b` are first
    divided by a[0].

    Examples
    --------
    The following code creates a lowpass Butterworth filter. Then it
    applies that filter to an array whose values are all 1.0; the
    output is also all 1.0, as expected for a lowpass filter.  If the
    `zi` argument of `lfilter` had not been given, the output would have
    shown the transient signal.

    >>> from numpy import array, ones
    >>> from scipy.signal import lfilter, lfilter_zi, butter
    >>> b, a = butter(5, 0.25)
    >>> zi = lfilter_zi(b, a)
    >>> y, zo = lfilter(b, a, ones(10), zi=zi)
    >>> y
    array([1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])

    Another example:

    >>> x = array([0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0])
    >>> y, zf = lfilter(b, a, x, zi=zi*x[0])
    >>> y
    array([ 0.5       ,  0.5       ,  0.5       ,  0.49836039,  0.48610528,
        0.44399389,  0.35505241])

    Note that the `zi` argument to `lfilter` was computed using
    `lfilter_zi` and scaled by `x[0]`.  Then the output `y` has no
    transient until the input drops from 0.5 to 0.0.

    """

    # FIXME: Can this function be replaced with an appropriate
    # use of lfiltic?  For example, when b,a = butter(N,Wn),
    #    lfiltic(b, a, y=numpy.ones_like(a), x=numpy.ones_like(b)).
    #

    # We could use scipy.signal.normalize, but it uses warnings in
    # cases where a ValueError is more appropriate, and it allows
    # b to be 2D.
    b = np.atleast_1d(b)
    if b.ndim != 1:
        raise ValueError("Numerator b must be rank 1.")
    a = np.atleast_1d(a)
    if a.ndim != 1:
        raise ValueError("Denominator a must be rank 1.")

    while len(a) > 1 and a[0] == 0.0:
        a = a[1:]
    if a.size < 1:
        raise ValueError("There must be at least one nonzero `a` coefficient.")

    if a[0] != 1.0:
        # Normalize the coefficients so a[0] == 1.
        a = a / a[0]
#.........这里部分代码省略.........
开发者ID:GaelVaroquaux,项目名称:scipy,代码行数:101,代码来源:signaltools.py

示例7:

import numpy as np
import scipy.linalg as la;
import matplotlib.pyplot as plt

P = [4,5,8,1]

c = la.companion(P)
eigenval,eigenvec=np.linalg.eig(c)

r = eigenval

print(eigenval)

x = []
y = []
for r1 in r:
	x.append(r1.real)
	y.append(r1.imag)	


plt.plot(x,y,'r.')
plt.axis("equal")
plt.show()

开发者ID:AlperenAydin,项目名称:TP_MATH,代码行数:23,代码来源:polynome.py

示例8:

from scipy import linalg as la
import numpy as np
x = np.roots([10,5,-5,1])
print x
a = la.companion([10,5,-5,1])
print a
b=la.eig(a)
print b
开发者ID:shivamkejriwal,项目名称:CS-357,代码行数:8,代码来源:comp.py


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