Random matrix generation

matgen unit contains subroutines for generation of random matrices with desired properties. It uses high-quality RNG to generate random numbers.

Contents

    1 Generation of random orthogonal matrices
    2 Multiplication by random orthogonal matrix
    3 Symmetric/Hermitian multiplication by random orthogonal matrix
    4 Generation of random matrix with desired condition number
    5 Downloads section

Generation of random orthogonal matrices

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(N3) time for NxN matrix generation.

Multiplication by random orthogonal matrix

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·N2)

Symmetric/Hermitian multiplication by random orthogonal matrix

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).

Generation of random matrix with desired condition number

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.

This article is licensed for personal use only.

Download ALGLIB for C++ / C# / Java / Python / ...

ALGLIB Project offers you two editions of ALGLIB:

ALGLIB Free Edition:
+delivered for free
+offers full set of numerical functionality
+extensive algorithmic optimizations
-no multithreading
-non-commercial license

ALGLIB Commercial Edition:
+flexible pricing
+offers full set of numerical functionality
+extensive algorithmic optimizations
+high performance (SMP, SIMD)
+commercial license with support plan

Links to download sections for Free and Commercial editions can be found below:

ALGLIB 4.01.0 for C++

C++ library.
Delivered with sources.
Monolithic design.
Extreme portability.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for C#

C# library with native kernels.
Delivered with sources.
VB.NET and IronPython wrappers.
Extreme portability.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for Java

Java wrapper around HPC core.
Delivered with sources.
Seamless integration with Java.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for Delphi

Delphi wrapper around C core.
Delivered as precompiled binary.
Compatible with FreePascal.
Editions:   FREE   COMMERCIAL

ALGLIB 4.01.0 for CPython

CPython wrapper around C core.
Delivered as precompiled binary.
Editions:   FREE   COMMERCIAL