-function A = random_positive_definite_matrix(integerN, max_entry = realmax)
+function A = random_positive_definite_matrix(integerN, max_entry = realmax, condmax=1000)
%
% Generate a random, symmetric positive-definite (SPD) matrix.
%
%
% - ``max_entry`` -- (optional) Upper bound on the entries.
%
+ % - ``condmax`` -- (optional, default=1000) Upper bound on
+ % the condition number; the matrix will be regenerated until
+ % its condition number is less or equal to ``condmax``.
+ %
% OUTPUT:
%
% - ``A`` -- A symmetric, positive definite matrix.
% provides unifrnd()
pkg load statistics;
- U = random_orthogonal_matrix(integerN);
- d = unifrnd(eps, max_entry, 1, integerN);
- D = diag(d);
- A = U*D*U';
+ A = zeros(integerN); % cond = Inf
+ while (cond(A) >= condmax)
+ U = random_orthogonal_matrix(integerN);
+ d = unifrnd(eps, max_entry, 1, integerN);
+ D = diag(d);
+ A = U*D*U';
+ end
end