Abstract
This paper concerns test matrices for numerical linear algebra using an errorfree transformation of floatingpoint arithmetic. For specified eigenvalues given by a user, we propose methods of generating a matrix whose eigenvalues are exactly known based on, for example, Schur or Jordan normal form and a block diagonal form. It is also possible to produce a real matrix with specified complex eigenvalues. Such test matrices with exactly known eigenvalues are useful for numerical algorithms in checking the accuracy of computed results. In particular, exact errors of eigenvalues can be monitored. To generate test matrices, we first propose an errorfree transformation for the product of three matrices Y SX. We approximate S by \({S^{\prime }}\) to compute \({YS^{\prime }X}\) without a rounding error. Next, the errorfree transformation is applied to the generation of test matrices with exactly known eigenvalues. Note that the exactly known eigenvalues of the constructed matrix may differ from the anticipated given eigenvalues. Finally, numerical examples are introduced in checking the accuracy of numerical computations for symmetric and unsymmetric eigenvalue problems.
Introduction
This paper concerns test matrices for numerical algorithms. If exact eigenvalues are known in advance, then it is useful for checking accuracy and stability of numerical methods for problems in numerical linear algebra. There are several matrices whose exact eigenvalues are known, for example, Circular, Clement, Frank, and tridiagonal Toeplitz matrices. Test matrices are well summarized in [4, Chapter 28]. This paper aims to generate a matrix with exactly known eigenvalues based on some standard forms, for example, the Schur or the Jordan normal forms, or a block diagonal form. Let \(X \in \mathbb {R}^{n \times n}\) be a nonsingular matrix. For a matrix \(S \in \mathbb {R}^{n \times n}\), we consider a form:
If (1) is the Schur normal form, X is an orthogonal matrix, and S is an upper triangular matrix. For the Jordan normal form, \(S \in \mathbb {R}^{n \times n}\) is a matrix whose diagonal blocks are Jordan matrices. It indicates that S is an upper bidiagonal matrix and the subdiagonal elements s_{i,i+ 1} are either 1 or 0. For both normal forms, the diagonal elements s_{ii} (1 ≤ i ≤ n) are eigenvalues of A.
Let \(\mathbb {F}\) be a set of floatingpoint numbers as defined in IEEE 754 [5]. If we use floatingpoint numbers and floatingpoint arithmetic, then there are following problems to get a matrix with exactly known eigenvalues using (1).
 Problem 1:

Even if all elements in a nonsingular matrix X can be represented by floatingpoint numbers (\(X \in \mathbb {F}^{n \times n}\)), elements in X^{− 1} may not be represented by floatingpoint numbers (\(X^{1} \not \in \mathbb {F}^{n \times n}\)).
 Problem 2:

Even if \(X, S, X^{1} \in \mathbb {F}^{n \times n}\), \(X^{1} S X \in \mathbb {F}^{n \times n}\) is not always satisfied.
We first prepare a diagonal matrix S and a nonsingular matrix X, next obtain the inverse matrix X^{− 1} using exact computations such as symbolic or rational arithmetic. Finally, we compute X^{− 1}SX using exact computations, and the result X^{− 1}SX is rounded to a floatingpoint matrix A. One may think s_{ii} (1 ≤ i ≤ n) are nearly eigenvalues of A, and these are useful as numerical tests. However, the BauerFike theorem [2] states
where λ and μ are eigenvalues of A and A + E = X^{− 1}SX, respectively. Therefore, s_{ii} can be far from the exact eigenvalues of A even if A is a floatingpoint matrix nearest to X^{− 1}SX. In addition, the cost of symbolic or rational arithmetic is much expensive compared to that of numerical computations.
We propose methods that produce a matrix with specified eigenvalues on the basis of an errorfree transformation of matrix multiplication. For a matrix \(S \in \mathbb {F}^{n \times n}\) given by a user, we approximate S by \(S^{\prime } \in \mathbb {F}^{n \times n}\), and obtain \(A:=X^{1} S^{\prime } X \in \mathbb {F}^{n \times n}\) using the proposed method. We prove that no rounding error occurs in evaluating a product of three matrices \(X^{1} S^{\prime } X\) using floatingpoint arithmetic. Hence, the exact eigenvalue of A can be known from the matrix \(S^{\prime }\).
This paper is organized as follows: In Section 2, basic theorems for floatingpoint numbers are introduced. In Section 3, we propose an errorfree transformation for a product of three floatingpoint matrices. In Section 4, several methods for generating test matrices with exactly known eigenvalues are proposed based on the theory in Section 3, and we introduce numerical examples in checking the accuracy of numerical computations.
Basics of floatingpoint arithmetic
Notation and basic lemmas on floatingpoint arithmetic are first introduced. Notations (⋅), _{▽}(⋅), and _{△}(⋅) indicate a computed result by floatingpoint arithmetic with rounding to nearest mode (roundTiesToEven), rounding downward mode (roundTowardNegative), and rounding upward mode (roundTowardPositive), respectively. Such rounding modes are defined in IEEE 754 [5]. We omit to write (⋅) for each operation for simplicity of description. For example, if we write ((a + b) + c) for \(a,b,c \in \mathbb {F}\), then it means ((a + b) + c). Assume that neither overflow nor underflow occurs in (⋅) and _{△}(⋅). Let and _{S} be a roundoff unit and the smallest positive number in \(\mathbb {F}\), respectively. A constant is the largest floatingpoint number in \(\mathbb {F}\). For example, \(\mathtt {u}=2^{53}, \mathtt {u}_{S}=2^{1074}\), and = 2^{1024}(1 −) for binary64 in IEEE 754. A function (a) for \(a \in \mathbb {R}\), the unit in the first place of the binary representation of a, is defined as
From the definition of the function, we have
We introduce several basic facts of floatingpoint numbers and floatingpoint arithmetic for \(a,b \in \mathbb {F}\) and \(x \in \mathbb {R}\):
The definition of the floatingpoint numbers by IEEE 754 immediately derives (4) and (5). The relation (6) and the proposition (7) are written in [8] and [3], respectively. In addition, the following lemmas are used in our proof.^{Footnote 1}
Lemma 1
For \(\sigma , a \in \mathbb {F}\), if (σ + a) ≥(σ), then \(\mathtt {fl}(\sigma +a) \in 2 \mathtt {u} \cdot \mathtt {ufp}(\sigma ) \mathbb {Z}\). In addition, \(\mathtt {fl}((\sigma +a)\sigma ) \in 2 \mathtt {u} \cdot \mathtt {ufp}(\sigma ) \mathbb {Z}\) holds true.
Proof
Using (4), (σ + a) ≤((σ + a)) from (8), and the assumption (σ + a) ≥(σ) in turn, we have
Because (9) and \(\sigma \in 2 \mathtt {u} \cdot \mathtt {ufp}(\sigma ) \mathbb {Z}\) from (4), \(\mathtt {fl}((\sigma +a)\sigma ) \in 2 \mathtt {u} \cdot \mathtt {ufp}(\sigma ) \mathbb {Z}\) is satisfied.
□
Applying Theorem 3.5 in [8] and an induction of binary tree described in [6], we can immediately obtain the following lemma.
Lemma 2
For \(p \in \mathbb {F}^{n}\), assume that \(p_{i} \in \mathtt {u} \sigma \mathbb {Z}\) for all i, where \(\sigma \in \mathbb {F}\) is a power of two. If \(\displaystyle \sum \limits _{i=1}^{n} p_{i} \le \sigma \), then no rounding error occurs in the sum by any orders.
We assume that divide and conquer methods by, for example, Strassen [9] and Winograd [11] are not applied for dot product, matrixvector, and matrixmatrix multiplication.
General theory for errorfree computations
For \(Y \in \mathbb {F}^{m \times n}, S \in \mathbb {F}^{n \times p}, X \in \mathbb {F}^{p \times q}\), we obtain a matrix \(S^{\prime } \in \mathbb {F}^{n \times p} (S^{\prime } \approx S)\) in order to compute \(YS^{\prime }X\) without a rounding error. This technique is applied to generation of test matrices with exactly known eigenvalues.
We set several constants as follows: We define ϕ_{ij} for x_{ij}≠ 0 and ψ_{ij} for y_{ij}≠ 0 such that
where all ϕ_{ij} and ψ_{ij} are powers of two. The constants ϕ_{ij} and ψ_{ij} imply the unit in the last nonzero bit of x_{ij} and y_{ij}, respectively. Exceptionally, we set ϕ_{ij} = 0 for x_{ij} = 0 and ψ_{ij} = 0 for y_{ij} = 0. Next, we set constants β,γ,𝜃,ω as follows:
These imply
for all (i,j) pairs. Note that β,γ,𝜃,ω ≥ 1 and \(\displaystyle \underset {k,j}{\max \limits } \phi _{kj}>0, \underset {i,k}{\max \limits } \psi _{ik}>0\), because both X and Y are nonsingular matrices.
If s_{ij} = 0 for all (i,j) pairs, then it is trivial that the matrix A is the zero matrix. Hence, we assume \(\displaystyle \max \limits _{i,j} s_{ij} > 0\). Let

n_{Y}: the maximum of the number of nonzero elements in row of Y,

n_{S}: the maximum of the number of nonzero elements in row of S,

n_{X}: the maximum of the number of nonzero elements in column of X.
We set \(n^{\prime } = {\min \limits } (n_{S}, n_{X})\). We define a constant σ as
where
Then,
is satisfied because all of β,γ,𝜃, and ω are powers of two. It is possible to set α as \(\displaystyle \mathtt {fl}_{\bigtriangleup } (n \cdot n^{\prime } \cdot \max \limits _{i{,j}} {s}_{ii})\) using floatingpoint arithmetic. A matrix \(S^{\prime }\) is computed by
We introduce several lemmas.
Lemma 3
For \(S \in \mathbb {F}^{n \times n}\), σ in (14), β and γ in (11), and ψ and ω in (12),
and
are satisfied for all (i,j) pairs.
Proof
From (16), the inequality (3), and α in (15), we have
Because \(n_{Y}, n^{\prime }, \beta , \gamma , \theta , \omega \ge 1\), the inequality (18) can be obtained.
For x_{ij} = 0 and y_{ij} = 0, the inequalities (19) are trivially satisfied. Therefore, we assume x_{ij}≠ 0 (ϕ_{ij}≠ 0) and y_{ij}≠ 0 (ψ_{ij}≠ 0) for the rest of the proof. From (11), (12), and (3), we have
for all (i,j) pairs. Then, using (13),
are satisfied for all (i,j) pairs. Therefore, (19) is proved.
□
Lemma 4
For \(S \in \mathbb {F}^{n \times n}\) and σ in (14),
is satisfied for all (i,j) pairs.
Proof
From β,γ,𝜃,ω ≥ 1, (3), and α≠ 0 from \(\displaystyle \max \limits _{i,j} s_{ij} > 0\), we have
Therefore, application of (20) and (21) yields
and using (22), (14), (23), and (16) gives
Therefore,
can be derived.
□
Lemma 5
Assume that \(s^{\prime }_{ij}\) is obtained by (17). Then,
is satisfied.
Proof
Using the definition of σ in (14) gives σ ≥s_{ij} for all (i,j) pairs. From this and (7), we derive
where δ≤⋅(σ + s_{ij}) = ⋅(σ) from (6) and Lemma 4. Therefore, from Lemma 3
□
We show that rounding error never occurs in the evaluation of \(Y{S}^{\prime }X\).
Theorem 1
Let \(\sigma \in \mathbb {F}\) be defined as in (14) from the matrices Y,X and S. Assume that \(4 n_{Y} \cdot n^{\prime } \cdot \mathtt {u} \beta \gamma \theta \omega \le 1\). If a matrix \(S^{\prime }\) is obtained by (17), then
Proof
First, we show \(\mathtt {fl}(S^{\prime }X)=S^{\prime }X\). If x_{ij} = 0, 1 ≤ i ≤ p for some j (the jth column vector of X is the zero vector), then
Hence, we assume there exists x_{ij}≠ 0 for any j for the rest of the proof. Since \(n_{Y}, n^{\prime }, \beta , \theta , \omega \ge 1\) and \(4 n_{Y} \cdot n^{\prime } \cdot \mathtt {u} \beta \gamma \theta \omega \le 1\) from the assumption, we have
Using Lemma 1 and (10) gives
and they yield
Next, we take an upper bound of \(\displaystyle \left  \sum \limits _{k=1}^{{p}} s_{ik}^{\prime } x_{kj} \right \) using Lemma 5, Lemma 3, and (24):
Therefore, from (26) and (28), Lemma 2 derives \(\mathtt {fl}({S}^{\prime }X)={S}^{\prime }X\).
Next, we focus on \(YS^{\prime }X\). The (i,j) element of \(YS^{\prime }X\) is
Therefore, we derive
Application of (27), Lemma 3, and \(\displaystyle 1 + 4 n_{Y} \cdot n^{\prime } \cdot \mathtt {u} \beta \gamma \theta \omega \le 2\) obtained from the assumption yields
Hence, from (29) and (30), Lemma 2 verifies \(\mathtt {fl}({Y} (S^{\prime } X)) = {Y} S^{\prime } X\).
□
If we change the definition of \(n^{\prime }\), it is possible to verify \(\mathtt {fl}(({Y} S^{\prime }) X) = {Y} S^{\prime } X\) similarly. Remark that the proposed method has reproducibility,^{Footnote 2} because there is no rounding error in any order of computations in \(\mathtt {fl}({Y} (S^{\prime } X))\).
Test matrices based on specified matrices
In this section, we introduce how to generate a matrix with exactly known eigenvalues. We prepare \(S, X, Y \in \mathbb {F}^{n \times n} \ (Y = X^{1})\). Assume that exact eigenvalues can be known quickly from the matrix S. For example, S is a diagonal matrix, triangular matrices, and tridiagonal Toeplitz matrix. We use MATLAB R2020a on Windows 10 with Intel(R) Core(TM) i78665U in numerical examples in this section.
We introduce a basic algorithm for the generation of test matrices using MATLABlike code on the basis of the discussion in Section 3. Greek alphabets cannot be used for variables on MATLAB. However, we exceptionally accept to use Greek alphabets in the description of algorithms for consistency with the theories in this paper.
In the algorithm, (⋅) at line 11 is not a builtin function in MATLAB. The calculation of (a) for \(a \in \mathbb {F}\) involves only three floatingpoint operations (see Algorithm 3.6 in [7]). Therefore, the cost for the ufp function is negligible. The function _ at line 6 in Algorithm 1 produces β and γ according to (11). The function _ similarly gives 𝜃 and ω based on (12).
To set multiple eigenvalues can be possible, because if s_{ij} = s_{kℓ}, then z_{ij} = z_{kℓ}. We can also generate a rank deficient matrix with exactly known eigenvalues. However, even if s_{ij}≠s_{kℓ}, z_{ij} = z_{kℓ} may be satisfied. It happens for relatively small s_{ij} compared to \(\displaystyle \max \limits _{i,j} s_{ij}\). If σ ≥s_{ij}, then z_{ij} = 0. In the worst case, the matrix Z becomes the zero matrix, and an obtained matrix A is useless. In addition, a test matrix with the specified singular values can be generated using Y = X^{T}.
Note that we can generate a real matrix with complex eigenvalues. Let i be the imaginary unit. The basic of linear algebra derives that a ± bi are eigenvalues of the following skewsymmetric matrix:
where
For a discussion of complex eigenvalues, we set 2by2 matrices to the diagonal block of D. For example, if \(a \pm b i, \ c \pm d i, e \ (a,b,c,d,e \in \mathbb {F})\) are expected eigenvalues, then we set a skewsymmetric matrix as
If one wants to obtain a matrix with exactly known eigenvectors, then we obtain the matrix as follows.
Note that
in some cases due to a problem of rounding error. Then, \(S^{\prime }\) is not a skewsymmetric matrix. To solve the problem, we compute only
and set \(s_{ji}^{\prime }=s_{ij}^{\prime }\) by copy of the computed result. For
Z is not a skewsymmetric matrix, while S is a skewsymmetric matrix.
The condition \(X, Y \in \mathbb {F}^{n \times n} \ (Y = X^{1})\) is very special. Therefore, we use specified matrices for X in (1) from the following sections.
Using weighing matrix
Assume that \(D \in \mathbb {F}^{n \times n}\) is a diagonal matrix (\(n^{\prime }=1\)). First, we use a weighing matrix. Let I be the identity matrix. If \(W \in \mathbb {R}^{n \times n}\) with weight \(c \in \mathbb {N}\) is a weighing matrix, W^{T}W = cI and w_{ij} ∈{− 1,0,1} for all (i,j) pairs. The weighing matrix is useful for the candidate of the matrix X, because β = γ = 𝜃 = ω = 1 in (11) and (12), and \(\displaystyle Y=X^{1}=\frac {1}{c}W^{T}\).
Let \(W_{n,c} \in \mathbb {F}^{n \times n}\) be a weighing matrix such that \(W^{T}_{n,c} W_{n,c} = c I\). The notation ⊗ means the Kronecker product. For \(\displaystyle n=\prod \limits _{i=1}^{w} n_{i}\) and \(\displaystyle c = \prod \limits _{i=1}^{w} c_{i}\), \(n_{i}, \ c_{i} \in \mathbb {N}\), a weighing matrix W_{n,c} can be obtained by \(W_{n_{1},c_{1}} \otimes W_{n_{2},c_{2}} \otimes {\dots } \otimes W_{n_{w},c_{w}}\).
If we set \(Y = \displaystyle \frac {1}{c} W_{n,c}^{T} = \frac {1}{c_{1}} W_{n_{1},c_{1}}^{T} \otimes {\dots } \otimes \frac {1}{c_{w}} W_{n_{w},c_{w}}^{T}\), then the matrix Y may not be representable in floatingpoint numbers. It happens when c is not a power of two. For a given diagonal matrix D, we obtain σ from \(\displaystyle \mathtt {fl} \left (\frac {1}{c}D \right )\) instead of D and compute
Then, we can compute \(\displaystyle W_{n,c}^{T} (D^{\prime } W_{n,c})=:A\) without rounding errors. Hence, \(c d_{ii}^{\prime }\) is the exact eigenvalue of the matrix A. Note that \(c d_{ii}^{\prime }\) may not be representable in the floatingpoint numbers. An errorfree transformation [3] produces floatingpoint vectors p and q such that
It is well known that we quickly obtain p and q using fused multiplyadd (FMA instruction defined in IEEE 754). The function (a,b,c) for \(a,b,c \in \mathbb {F}\) provides a nearest floatingpoint number of ab + c. Then,
Hadamard matrix, the special case of weighing matrix (c = n), is very useful for the candidate of X.
The following codes generate a test matrix on MATLAB. Let \(d \in \mathbb {F}^{n}\) be a vector with expected eigenvalues. The exact eigenvalue of \(A \in \mathbb {F}^{n \times n}\) is p_{i} + q_{i} ≈ d_{i}. Note that the function hadamard on MATLAB R2020a in the following algorithm works when n, n/12 or n/20 is a power of two.^{Footnote 3}
Note that Algorithm 2 produces a real symmetric matrix. For \(n \in \mathbb {F}\) and \(y \in \mathbb {F}^{n}\), the function at line 12 transforms ny to \(p+q, \ p,q \in \mathbb {F}^{n}\). If n is a power of two, q at line 12 is the zero vector.
At line 11, a matrix multiplication is computed. In the special cases, we can reduce the cost of the matrix multiplication. Let H_{n} be a Hadamard matrix with dimension n. We can generate one of 2nby2n Hadamard matrices by the following manner [10]
For a diagonal matrix \(D \in \mathbb {F}^{2n \times 2n}\), there exist matrices \(M, N \in \mathbb {R}^{n \times n}\) such that
where D_{1} and D_{2} are nbyn diagonal matrices. Then, the matrices M and N can quickly be obtained, because D_{1} and D_{2} are diagonal matrices. Finally, we compute \(H_{2n}^{T} D H_{2n}\) by
Therefore, we only compute \({H_{n}^{T}} M = {H_{n}^{T}} D_{1} {H_{n}^{T}}\) and \({H_{n}^{T}} N = {H_{n}^{T}} D_{2} {H_{n}^{T}}\) as matrix multiplications to obtain \(H^{T}_{2n} D H_{2n}\). The cost of matrix multiplications can be reduced using this technique recursively.
Let r ⋅ n be a matrix size for the output, where \(r, n \in \mathbb {N}\) and r is a power of two.
where \(D_{i} \in \mathbb {F}^{n \times n}\), 1 ≤ i ≤ r are diagonal matrices, and O is the zero matrix.
Then, we only compute the following r matrix multiplications:
and C_{ij} is obtained by
The total cost becomes \(2 k n^{3} + \mathcal {O}(n^{2}+k)\) floatingpoint operations for rbyr block division. Note that the original cost without block computations is \(2 (k n)^{3} + \mathcal {O}((kn)^{2})\), that is much expensive compared to block computations for large k.
We introduce an algorithm producing a matrix with eigenvalues based on the block computations.
We show numerical examples for the performance using this technique. Figures 1 and 2 show computing times with rbyr block computations. r = 1 means a computing time for Algorithm 2. Computing times for solving linear systems () and eigenvalue problems () using MATLAB are shown for comparison. Note that in this example produces only approximate eigenvalues such that d = (A). The figures indicate that computing time for the generation of test matrices is much shorter than that for solving linear systems and that for eigenvalue problems.
Remark 1
We mentioned that MATLAB’s hadamard function works in the case that n, n/12, or n/20 is the power of two. Even if n does not satisfy that restriction, the test matrices can be generated. Assume that H_{k} exists and k < n. Let \(P \in \mathbb {R}^{(nk) \times (nk)}\) be a permutation matrix. We generate
instead of the Hadamard matrix. Then, \(D^{\prime }\) is obtained by
The exact eigenvalue is \(k d_{ii}^{\prime }\) for 1 ≤ i ≤ k and \(d^{\prime }_{ii}\) for k + 1 ≤ i ≤ n.
We checked the accuracy of approximate eigenvalues obtained by . The vector \(d \in \mathbb {F}^{n}, \ n=4096\) in Algorithm 2 is set as follows.
 Ex.1::

d_{1} = 1, d_{n} = 10^{10}, intermediate values d_{i}, 2 ≤ i ≤ n − 1, are geometrically distributed.
 Ex.2::

d_{i} = 1, d_{n} = 10^{10}, 1 ≤ i ≤ n − 1.
We compare accuracy of eigenvalues by d = (A) and [V,D] = (A) in MATLAB. Let \(\hat \lambda _{1} \le \hat \lambda _{2} \le {\dots } \le \hat \lambda _{n}\) be computed eigenvalues. Figures 3 and 4 show relative errors
for all i, where p and q are obtained by Algorithm 2. From Fig. 3 for Ex.1, the accuracy of relatively small eigenvalue tends to be worse. Besides, approximate eigenvalues from [V,D] = (A) are better than those from d = (A) in terms of accuracy. In the case of Ex.2, we can see from Fig. 4 that some of the eigenvalues are not so accurate, and several computed eigenvalues are exact.
Using the Hadamard matrix, we introduce an algorithm generating a test matrix based on the Jordan normal form (\(n^{\prime }=2\)).
We show numerical examples using Algorithm 4. The vectors \(v \in \mathbb {F}^{n}\) and \(w \in \mathbb {F}^{n1}\) for n = 4096 as arguments of Algorithm 4 are set as follows:
 Ex.3::

\(v_{1}=1, \ v_{i} = 10^{5}, \ 2 \le i \le n, \ w=(1,1,\dots ,1)^{T}\).
 Ex.4::

\(v_{i}=1, \ 1 \le i \le n1, \ v_{n} = 10^{5}, \ w=(1,1,\dots ,1)^{T}\).
Then, we execute [A,p,q] = _(v,w). Figures 5 and 6 show the quantity (31) for all i, respectively. Approximate eigenvalues for these numerical examples have small imaginary parts so that we checked the accuracy of the real part of the computed eigenvalues. In both cases, the matrices have n − 1 multiple eigenvalues, but there are differences in the numerical examples. From Fig. 6, computed eigenvalues for n − 1 small eigenvalues are very inaccurate.
Eigenvector matrix X using random integer matrices
We use the LU decomposition and generate integer matrices^{Footnote 4} for X. Let L and U be a unit lower triangular matrix and a unit upper triangular matrix, respectively. We generate X = LU, where we set L and U as 01 matrices in order to obtain small constants β, γ, 𝜃, and ω. Then, Y = X^{− 1} is also an integer matrix. Because L and U are 01 matrices, there is no rounding error in (LU) up to n = ^{− 1}. On the other hand, the problem is that the exact Y = X^{− 1} can be obtained or not. Let \(\tilde Y\) be a numerically obtained result for X^{− 1}. If \(\textbf {O} = \mathtt {fl}_{\bigtriangledown } (\tilde Y X  I) = \mathtt {fl}_{\bigtriangleup } (\tilde Y X  I)\), where I is the identity matrix, then \(\tilde Y = X^{1}\). Using MATLAB notation, L and U are given as
where 0 ≤ k ≤ 1 is density of a matrix. The sparsity of L and U is controlled by \(k \in \mathbb {N}\).
The following algorithm generates A using random integer matrices.
We introduce numerical examples for Algorithm 5. We set n = 1,000,5,000, and \(d \in \mathbb {F}^{n}\) is generated by (n,1) using MATLAB R2020a. Table 1 shows

The product of four constants βγ𝜃ω

The 2norm condition number of X, i.e., ∥X^{− 1}∥_{2}∥X∥_{2} = ∥Y ∥_{2}∥X∥_{2}

The relative change between d_{i} and r_{i}, i.e., \(\displaystyle \max \limits _{i} \frac {d_{i}r_{i}}{d_{i}}\)

The density of the matrix A, i.e., the number of nonzero elements of A divided by n^{2}
for each k. The numbers in Tables 1 and 2 are averages of 10 examples. If k is small, we can obtain small βγ𝜃ω. It makes the relative change for v small. If k becomes large, then

The relative change for a small absolute value,

The condition number of X, and

Density of A
also become large.
Conclusion
We proposed methods generating matrices with specified eigenvalues based on the errorfree transformation of floatingpoint numbers. They are useful for checking the accuracy and stability of numerical algorithms. Finally, we provided several possibilities for an eigenvector matrix and showed how to generate a real matrix with complex eigenvalues. The discussion can be extended to the generation of test matrices with complex eigenvalues and eigenvectors.
Notes
 1.
Thanks to Dr. Atsushi Minamihata for the discussion.
 2.
Reproducibility means ability to obtain always bitwise identical results on the same input data on the same or different architectures [1].
 3.
This is not only for MATLAB R2020a, but also for more early versions.
 4.
We appreciate Prof. Siegfried M. Rump’s advice for this discussion.
References
 1.
Ahrens, P., Nguyen, H.D., Demmel, J.: Efficient Reproducible Floating Point Summation and BLAS, EECS Department, UC Berkeley, Technical Report No. UCB/EECS2016121 Berkeley (2016)
 2.
Bauer, F.L., Fike, C.T.: Norms and exclusion theorems. Numer. Math. 2, 137–141 (1960)
 3.
Dekker, T.J.: A floatingpoint technique for extending the available precision. Numer. Math. 18, 224–242 (1971)
 4.
Higham, N.J.: Accuracy and Stability of Numerical Algorithms, 2nd edn. SIAM, Philadelphia (2002)
 5.
IEEE Standard for FloatingPoint Arithmetic: Std 7542019 (2019)
 6.
Jeannerod, C. P., Rump, S.M.: Improved error bounds for inner products in floatingpoint arithmetic. SIAM J. Matrix Anal. & Appl. (SIMAX) 34, 338–344 (2013)
 7.
Rump, S.M.: Error estimation of floatingpoint summation and dot product. BIT Numer. Math. 52, 201–220 (2012)
 8.
Rump, S.M., Ogita, T., Oishi, S.: Accurate floatingpoint summation part I: faithful rounding. SIAM J. Sci. Comput. 31, 189–224 (2008)
 9.
Strassen, V.: Gaussian elimination is not optimal. Numer. Math. 13, 354–356 (1969)
 10.
Sylvester, J.J.: Thoughts on inverse orthogonal matrices, simultaneous sign successions, and tessellated pavements in two or more colours, with applications to Newton’s rule, ornamental tilework, and the theory of numbers. Philos. Mag. 34, 461–475 (1867)
 11.
Winograd, S.: On multiplication of 2x2 matrices. Linear Algebra Its Appl. 4, 381–388 (1971)
Acknowledgements
This research is partially supported by JST / CREST and JSPS Kakenhi (20H04195). We sincerely express our thanks to the reviewer for the fruitful comments and Dr. Takeshi Terao for his kind advice of simplified codes of MATLAB.
Author information
Affiliations
Corresponding author
Additional information
Publisher’s note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Ozaki, K., Ogita, T. Generation of test matrices with specified eigenvalues using floatingpoint arithmetic. Numer Algor (2021). https://doi.org/10.1007/s11075021011867
Received:
Accepted:
Published:
Keywords
 Test matrices
 Floatingpoint arithmetic
 Numerical linear algebra
 Eigenvalue problems