![]() |
matgen unit contains subroutines for generation of random matrices with desired properties. It uses high-quality RNG to generate random numbers.
This task is solved by rmatrixrndorthogonal and cmatrixrndorthogonal functions. Their result is a random real or random complex matrix, which is Haar distributed. This function is moderately stable, even for large matrices, but orthogonality up to machine precision is not guaranteed. Moderate accuracy loss is possible. These subroutines require O(N 3) time for NxN matrix generation.
rmatrixrndorthogonalfromtheleft, rmatrixrndorthogonalfromtheright, cmatrixrndorthogonalfromtheleft and cmatrixrndorthogonalfromtheright subroutines multiply rectangular matrix by random orthogonal matrix. Multiplication is done either from the left or from the right. These functions have same restrictions as random matrix generation subroutines mentioned above. If size of matrix being multiplied is M*N, and random matrix size is N*N, then complexity of multiplication is O(M·N 2)
If you want to make operation B=Q'·A·Q where A is Hermitian (symmetric) and Q is random orthogonal, you have two options. You can generate Q explicitly and multiply matrices, or you can use smatrixrndmultiply/hmatrixrndmultiply subroutines which implements this operation in a compact and efficient manner.
Note #1
Unline many functions for linear algebra operations with symmetric matrices, these functions reqire that FULL matrix A is given (not just upper/lower half).
cmatrixrndcond, rmatrixrndcond, smatrixrndcond, hmatrixrndcondm spdmatrixrndcond and hpdmatrixrndcond functions may be used to generate random matrix with desired condition number. Matrix may belong to one of the following classes: general complex, general real, symmetric real, Hermitian, SPD, HPD.
Note #2
Random matrix generation is implemented as generation of diagonal matrix with desired eigenvalue distribution, whish is multiplied by a random orthogonal matrix.
| C++ | matgen subpackage | |
| C# | matgen subpackage |
This article is intended for personal use only.
C# source.
C++ source.
C++ source. MPFR/GMP is used.
GMP source is available from gmplib.org. MPFR source is available from www.mpfr.org.
FreePascal version.
Delphi version.
VB.NET version.
VBA version.
Python version (CPython and IronPython are supported).
|
ALGLIB® - numerical analysis library, 1999-2012. |