Last active
October 11, 2022 20:52
-
-
Save bstellato/23322fe5d87bb71da922fbc41d658079 to your computer and use it in GitHub Desktop.
Generate matrix with predefined condition number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Construct random matrix P with specified condition number | |
# | |
# Bierlaire, M., Toint, P., and Tuyttens, D. (1991). | |
# On iterative algorithms for linear ls problems with bound constraints. | |
# Linear Algebra and Its Applications, 143, 111–143. | |
# | |
cond_P = 10**2 # Condition number | |
log_cond_P = np.log(cond_P) | |
exp_vec = np.arange(-log_cond_P/4., log_cond_P * (n + 1)/(4 * (n - 1)), log_cond_P/(2.*(n-1))) | |
s = np.exp(exp_vec) | |
S = np.diag(s) | |
U, _ = la.qr((np.random.rand(n, n) - 5.) * 200) | |
V, _ = la.qr((np.random.rand(n, n) - 5.) * 200) | |
P = U.dot(S).dot(V.T) | |
P = P.dot(P.T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will fail for some combinations of matrix size and condition number, e.g.
n = 4
,cond_P = 23
. Truncateexp_vec
to sizen
to fix it with