bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / linalg / _decomp_qz / qz
function
scipy.linalg._decomp_qz:qz
source: build-install/usr/lib/python3.14/site-packages/scipy/linalg/_decomp_qz.py:159
Signature
def qz(A, B, output = real, lwork = <object object at 0x0000>, sort = None, overwrite_a = False, overwrite_b = False, check_finite = True)Summary
QZ decomposition for generalized eigenvalues of a pair of matrices.
Extended Summary
The QZ, or generalized Schur, decomposition for a pair of n-by-n matrices (A,B) is
(A,B) = (Q @ AA @ Z*, Q @ BB @ Z*)where AA, BB is in generalized Schur form if BB is upper-triangular with non-negative diagonal and AA is upper-triangular, or for real QZ decomposition (output='real') block upper triangular with 1x1 and 2x2 blocks. In this case, the 1x1 blocks correspond to real generalized eigenvalues and 2x2 blocks are 'standardized' by making the corresponding elements of BB have the form
[ a 0 ] [ 0 b ]
and the pair of corresponding 2x2 blocks in AA and BB will have a complex conjugate pair of generalized eigenvalues. If (output='complex') or A and B are complex matrices, Z' denotes the conjugate-transpose of Z. Q and Z are unitary matrices.
The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details. The NEP 5 signature of this function is (i,i),(i,i)->(i,i),(i,i),(i,i),(i,i).
Parameters
A: (N, N) array_like2-D array to decompose
B: (N, N) array_like2-D array to decompose
output: {'real', 'complex'}, optionalConstruct the real or complex QZ decomposition for real matrices. Default is 'real'.
lwork: int, optionalWork array size. If None or -1, it is automatically computed.
sort: {None, callable, 'lhp', 'rhp', 'iuc', 'ouc'}, optionalNOTE: THIS INPUT IS DISABLED FOR NOW. Use ordqz instead.
Specifies whether the upper eigenvalues should be sorted. A callable may be passed that, given an eigenvalue, returns a boolean denoting whether the eigenvalue should be sorted to the top-left (True). For real matrix pairs, the sort function takes three real arguments (alphar, alphai, beta). The eigenvalue
x = (alphar + alphai*1j)/beta. For complex matrix pairs or output='complex', the sort function takes two complex arguments (alpha, beta). The eigenvaluex = (alpha/beta). Alternatively, string parameters may be used:'lhp' Left-hand plane (x.real < 0.0)
'rhp' Right-hand plane (x.real > 0.0)
'iuc' Inside the unit circle (x*x.conjugate() < 1.0)
'ouc' Outside the unit circle (x*x.conjugate() > 1.0)
Defaults to None (no sorting).
overwrite_a: bool, optionalWhether to overwrite data in a (may improve performance) See tutorial_linalg_overwrite for details.
overwrite_b: bool, optionalWhether to overwrite data in b (may improve performance) See tutorial_linalg_overwrite for details.
check_finite: bool, optionalIf true checks the elements of
AandBare finite numbers. If false does no checking and passes matrix through to underlying algorithm.
Returns
AA: (N, N) ndarrayGeneralized Schur form of A.
BB: (N, N) ndarrayGeneralized Schur form of B.
Q: (N, N) ndarrayThe left Schur vectors.
Z: (N, N) ndarrayThe right Schur vectors.
Notes
Q is transposed versus the equivalent function in Matlab.
Examples
import numpy as np from scipy.linalg import qz✓
A = np.array([[1, 2, -1], [5, 5, 5], [2, 4, -8]]) B = np.array([[1, 1, -3], [3, 1, -1], [5, 6, -2]])✓
AA, BB, Q, Z = qz(A, B)
✓AA BB Q Z✗
array([[-0.68, 0.64, -0.37],
[ 0.7 , 0.71, -0.07],
[ 0.22, -0.31, -0.93]])
Verify the QZ decomposition. With real output, we only need the
transpose of ``Z`` in the following expressions.
Q @ AA @ Z.T # Should be A Q @ BB @ Z.T # Should be B✓
array([[ 1., 1., -3.],
[ 3., 1., -1.],
[ 5., 6., -2.]])
Repeat the decomposition, but with ``output='complex'``.
AA, BB, Q, Z = qz(A, B, output='complex')
✓np.set_printoptions(precision=3, suppress=True)
✓AA BB Q Z✗
array([[ 0.596+0.32j , -0.31 +0.414j, 0.393-0.347j],
[-0.619-0.332j, -0.479+0.314j, 0.154-0.393j],
[-0.195-0.104j, 0.576+0.27j , 0.715+0.187j]])
With complex arrays, we must use ``Z.conj().T`` in the following
expressions to verify the decomposition.
Q @ AA @ Z.conj().T # Should be A Q @ BB @ Z.conj().T # Should be B✗
array([[ 1.-0.j, 1.-0.j, -3.+0.j],
[ 3.+0.j, 1.-0.j, -1.+0.j],
[ 5.-0.j, 6.-0.j, -2.+0.j]])
See also
Aliases
scipy.linalg.qz