![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/lib/python3.6/dist-packages/sympy/matrices/expressions/tests/ |
Upload File : |
from sympy.core.expr import unchanged from sympy.core.symbol import Symbol, symbols from sympy.matrices.immutable import ImmutableDenseMatrix from sympy.matrices.expressions.companion import CompanionMatrix from sympy.polys.polytools import Poly from sympy.testing.pytest import raises def test_creation(): x = Symbol('x') y = Symbol('y') raises(ValueError, lambda: CompanionMatrix(1)) raises(ValueError, lambda: CompanionMatrix(Poly([1], x))) raises(ValueError, lambda: CompanionMatrix(Poly([2, 1], x))) raises(ValueError, lambda: CompanionMatrix(Poly(x*y, [x, y]))) unchanged(CompanionMatrix, Poly([1, 2, 3], x)) def test_shape(): c0, c1, c2 = symbols('c0:3') x = Symbol('x') assert CompanionMatrix(Poly([1, c0], x)).shape == (1, 1) assert CompanionMatrix(Poly([1, c1, c0], x)).shape == (2, 2) assert CompanionMatrix(Poly([1, c2, c1, c0], x)).shape == (3, 3) def test_entry(): c0, c1, c2 = symbols('c0:3') x = Symbol('x') A = CompanionMatrix(Poly([1, c2, c1, c0], x)) assert A[0, 0] == 0 assert A[1, 0] == 1 assert A[1, 1] == 0 assert A[2, 1] == 1 assert A[0, 2] == -c0 assert A[1, 2] == -c1 assert A[2, 2] == -c2 def test_as_explicit(): c0, c1, c2 = symbols('c0:3') x = Symbol('x') assert CompanionMatrix(Poly([1, c0], x)).as_explicit() == \ ImmutableDenseMatrix([-c0]) assert CompanionMatrix(Poly([1, c1, c0], x)).as_explicit() == \ ImmutableDenseMatrix([[0, -c0], [1, -c1]]) assert CompanionMatrix(Poly([1, c2, c1, c0], x)).as_explicit() == \ ImmutableDenseMatrix([[0, 0, -c0], [1, 0, -c1], [0, 1, -c2]])