Back to Core Functions

gallery

Test matrices by name

Syntax

A = gallery(matname)
A = gallery(matname, n)
A = gallery(matname, n, ...)

Description

Generates test matrices useful for testing numerical algorithms. The first argument is a string specifying the matrix type. Available types include: 'hilb' (Hilbert), 'invhilb' (inverse Hilbert), 'pascal', 'magic', 'lehmer', 'minij', 'moler', 'pei', 'kms', 'cauchy', 'circul', 'fiedler', 'tridiag', 'frank', 'grcar', 'hanowa', 'jordbloc', 'clement', 'triw', 'parter'.

Parameters

NameDescription
matnameName of the test matrix type (string)
n(optional)Size or first parameter (depends on matrix type)
...(optional)Additional parameters (depends on matrix type)

Returns

Test matrix of the specified type

Examples

Try It
>> gallery('hilb', 4)
4×4 Hilbert matrix
Try It
>> gallery('pascal', 5)
5×5 Pascal matrix
Try It
>> gallery('lehmer', 3)
1.0000  0.5000  0.3333
0.5000  1.0000  0.6667
0.3333  0.6667  1.0000
Try It
>> gallery('pei', 3, 2)
3×3 Pei matrix with alpha=2
Try It
>> gallery('kms', 4, 0.5)
4×4 KMS Toeplitz matrix with rho=0.5

See Also