arb_mat – matrices over real numbers¶
-
class
flint.
arb_mat
¶ Represents a matrix over the real numbers.
>>> A = arb_mat([[1,2],[3,4]]) ** 2 / 5 >>> A [[1.40000000000000 +/- 3.12e-16], 2.00000000000000] [ 3.00000000000000, [4.40000000000000 +/- 1.43e-15]] >>> print(A.str(5, radius=False)) [1.4000, 2.0000] [3.0000, 4.4000]
-
charpoly
(s)¶ Returns the characteristic polynomial of s as an arb_poly.
>>> print(arb_mat(2, 2, [1, 1, 1, 0]).charpoly()) 1.00000000000000*x^2 + (-1.00000000000000)*x + (-1.00000000000000)
-
chop
(s, tol)¶ Returns a copy of s where entries that are bounded by tol in magnitude have been replaced by exact zeros.
>>> print(arb_mat.stirling(4, 4).inv().str(5, radius=False)) [1.0000, 0, 0, 0] [ 0, 1.0000, [+/- 1.20e-15], [+/- 5.00e-16]] [ 0, -1.0000, 1.0000, [+/- 1.67e-16]] [ 0, 1.0000, -3.0000, 1.0000] >>> print(arb_mat.stirling(4, 4).inv().chop(1e-6).str(5, radius=False)) [1.0000, 0, 0, 0] [ 0, 1.0000, 0, 0] [ 0, -1.0000, 1.0000, 0] [ 0, 1.0000, -3.0000, 1.0000]
-
contains
(s, t)¶ Returns whether t is contained in s (in the sense of balls).
>>> A = arb_mat([[1,2],[3,4]]) >>> ((A / 3) * 3).contains(A) True >>> A.contains((A / 3) * 3) False >>> ((A / 3) * 3).contains(fmpz_mat([[1,2],[3,4]])) True >>> ((A / 3) * 3).contains(fmpz_mat([[1,2],[3,5]])) False >>> (A / 3).contains(fmpq_mat([[1,2],[3,4]]) / 3) True
-
convert
(type cls, x)¶ Attempts to convert x to an arb_mat, raising TypeError if unsuccessful.
-
convert_operand
(type cls, x)¶ Attempts to convert x to an arb_mat, returning NotImplemented if unsuccessful.
-
dct
(type cls, long n, long m=-1)¶ Returns the size n by n DCT matrix (optionally a separate number of columns m can be given in which case the periodic extension of the smaller dimension is used).
>>> print(arb_mat.dct(4).str(4)) [ 0.5000, 0.5000, 0.5000, 0.5000] [[0.6533 +/- 1.86e-5], [0.2706 +/- 1.96e-6], [-0.2706 +/- 1.96e-6], [-0.6533 +/- 1.86e-5]] [ [0.5000 +/- 3e-9], [-0.5000 +/- 3e-9], [-0.5000 +/- 3e-9], [0.5000 +/- 3e-9]] [[0.2706 +/- 1.96e-6], [-0.6533 +/- 1.86e-5], [0.6533 +/- 1.86e-5], [-0.2706 +/- 1.96e-6]]
-
det
(s)¶ Returns the determinant of the square matrix s as an arb.
>>> A = arb_mat(3, 3, range(9)) >>> showgood(lambda: A.det(), dps=25) # exact singular 0 >>> A[2,2] = 10 >>> showgood(lambda: A.det(), dps=25) -6.000000000000000000000000 >>> showgood(lambda: (A * A).det()) 36.0000000000000 >>> print(arb_mat(0, 0).det()) 1.00000000000000
-
eig
(s, *args, **kwargs)¶ Computes eigenvalues and/or eigenvectors of this matrix. This is just a wrapper for
acb_mat.eig()
; see the documentation for that method for details.
-
entries
(self)¶
-
exp
(s)¶ Returns the matrix exponential of s.
>>> print(arb_mat(2, 2, [1, 4, -2, 1]).exp()) [ [-2.58607310345045 +/- 5.06e-15], [1.18429895089106 +/- 1.15e-15]] [[-0.592149475445530 +/- 5.73e-16], [-2.58607310345045 +/- 5.06e-15]]
-
hilbert
(type cls, long n, long m)¶ Returns the n by m truncated Hilbert matrix.
>>> arb_mat.hilbert(6,2) [ 1.00000000000000, 0.500000000000000] [ 0.500000000000000, [0.333333333333333 +/- 3.71e-16]] [[0.333333333333333 +/- 3.71e-16], 0.250000000000000] [ 0.250000000000000, [0.200000000000000 +/- 4.45e-17]] [[0.200000000000000 +/- 4.45e-17], [0.166666666666667 +/- 3.71e-16]] [[0.166666666666667 +/- 3.71e-16], [0.142857142857143 +/- 1.79e-16]]
-
inv
(s, bool nonstop=False)¶ Returns the inverse matrix of the square matrix s.
If s is numerically singular, raises
ZeroDivisionError
unless nonstop is set in which case a matrix with NaN entries is returned.>>> A = arb_mat(2, 2, [1, 5, 2, 4]) >>> print(A * A.inv()) [[1.00000000000000 +/- 6.11e-16], [+/- 3.34e-16]] [ [+/- 4.45e-16], [1.00000000000000 +/- 5.56e-16]] >>> A = arb_mat(2, 2, [1, 5, 2, 10]) >>> A.inv() Traceback (most recent call last): ... ZeroDivisionError: matrix is singular >>> A.inv(nonstop=True) [nan, nan] [nan, nan]
-
mid
(s)¶ Returns the matrix consisting of the midpoints of the entries of s.
>>> arb_mat([["1.5 +/- 0.1", 3]]).mid() [1.50000000000000, 3.00000000000000]
-
ncols
(s) → long¶ Returns the number of columns of s.
-
nrows
(s) → long¶ Returns the number of rows of s.
-
overlaps
(s, arb_mat t)¶ Returns whether s and t overlap (in the sense of balls).
>>> A = arb_mat([[1,2],[3,4]]) >>> ((A / 3) * 3).overlaps(A) True >>> ((A / 3) * 3 + 0.0001).overlaps(A) False
-
pascal
(type cls, long n, long m, int triangular=0)¶ Returns the n by m truncated Pascal matrix. If triangular is 0, the symmetric version of this matrix is returned; if triangular is -1 or 1, the lower or upper triangular version of the Pascal matrix is returned.
>>> arb_mat.pascal(3, 4) [1.00000000000000, 1.00000000000000, 1.00000000000000, 1.00000000000000] [1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000] [1.00000000000000, 3.00000000000000, 6.00000000000000, 10.0000000000000] >>> arb_mat.pascal(3, 4, 1) [1.00000000000000, 1.00000000000000, 1.00000000000000, 1.00000000000000] [ 0, 1.00000000000000, 2.00000000000000, 3.00000000000000] [ 0, 0, 1.00000000000000, 3.00000000000000] >>> arb_mat.pascal(3, 4, -1) [1.00000000000000, 0, 0, 0] [1.00000000000000, 1.00000000000000, 0, 0] [1.00000000000000, 2.00000000000000, 1.00000000000000, 0]
-
repr
(self)¶
-
solve
(s, t, bool nonstop=False, algorithm=None)¶ Solves \(AX = B\) where A is a square matrix given by s and \(B\) is a matrix given by t.
If A is numerically singular, raises
ZeroDivisionError
unless nonstop is set in which case a matrix with NaN entries is returned.>>> A = arb_mat(2, 2, [1, 2, 3, 4]) >>> X = arb_mat(2, 3, range(6)) >>> B = A * X >>> print(A.solve(B)) [ [+/- 4.74e-15], [1.00000000000000 +/- 4.78e-15], [2.00000000000000 +/- 8.52e-15]] [[3.00000000000000 +/- 3.56e-15], [4.00000000000000 +/- 3.59e-15], [5.00000000000000 +/- 6.28e-15]] >>> arb_mat([[1,1],[0,0]]).solve(arb_mat(2,3)) Traceback (most recent call last): ... ZeroDivisionError: singular matrix in solve() >>> arb_mat([[1,1],[0,0]]).solve(arb_mat(2,3), nonstop=True) [nan, nan, nan] [nan, nan, nan]
The optional algorithm can be None (default), “lu”, or “precond”. It can also be set to “approx” in which case an approximate floating-point solution (warning: without error bounds!) is returned.
-
stirling
(type cls, long n, long m, int kind=0)¶ Returns the n by m truncated Stirling matrix. The parameter kind can be 0 for unsigned Stirling numbers of the first kind, 1 for signed Stirling numbers of the first kind, and 2 for Stirling numbers of the second kind.
>>> arb_mat.stirling(5, 4) [1.00000000000000, 0, 0, 0] [ 0, 1.00000000000000, 0, 0] [ 0, 1.00000000000000, 1.00000000000000, 0] [ 0, 2.00000000000000, 3.00000000000000, 1.00000000000000] [ 0, 6.00000000000000, 11.0000000000000, 6.00000000000000] >>> arb_mat.stirling(5, 4, 1) [1.00000000000000, 0, 0, 0] [ 0, 1.00000000000000, 0, 0] [ 0, -1.00000000000000, 1.00000000000000, 0] [ 0, 2.00000000000000, -3.00000000000000, 1.00000000000000] [ 0, -6.00000000000000, 11.0000000000000, -6.00000000000000] >>> arb_mat.stirling(5, 4, 2) [1.00000000000000, 0, 0, 0] [ 0, 1.00000000000000, 0, 0] [ 0, 1.00000000000000, 1.00000000000000, 0] [ 0, 1.00000000000000, 3.00000000000000, 1.00000000000000] [ 0, 1.00000000000000, 7.00000000000000, 6.00000000000000]
-
str
(self, *args, **kwargs)¶
-
table
(self)¶
-
tolist
()¶ flint_mat.table(self)
-
trace
(s)¶ Returns the trace of the square matrix s as an arb.
>>> arb_mat([[3,4],[5,7]]).trace() 10.0000000000000
-
transpose
(s)¶ Returns the transpose of s.
-