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

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

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.

*This article is licensed for personal use only.*

ALGLIB Project offers you two editions of ALGLIB:

**ALGLIB Free Edition**:

delivered for free

offers full set of numerical functionality

extensive algorithmic optimizations

no low level optimizations

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:

C++ library.

Delivered with sources.

Monolithic design.

Extreme portability.

Delivered with sources.

Monolithic design.

Extreme portability.

C# library with native kernels.

Delivered with sources.

VB.NET and IronPython wrappers.

Extreme portability.

Delivered with sources.

VB.NET and IronPython wrappers.

Extreme portability.

Delphi wrapper around C core.

Delivered as precompiled binary.

Compatible with FreePascal.

Delivered as precompiled binary.

Compatible with FreePascal.

CPython wrapper around C core.

Delivered as precompiled binary.

Delivered as precompiled binary.