# hermiteForm

Hermite form of matrix

## Description

example

H = hermiteForm(A) returns the Hermite normal form of a matrix A. The elements of A must be integers or polynomials in a variable determined by symvar(A,1). The Hermite form H is an upper triangular matrix.

example

[U,H] = hermiteForm(A) returns the Hermite normal form of A and a unimodular transformation matrix U, such that H = U*A.

example

___ = hermiteForm(A,var) assumes that the elements of A are univariate polynomials in the specified variable var. If A contains other variables, hermiteForm treats those variables as symbolic parameters.

You can use the input argument var in any of the previous syntaxes.

If A does not contain var, then hermiteForm(A) and hermiteForm(A,var) return different results.

## Examples

### Hermite Form for Matrix of Integers

Find the Hermite form of an inverse Hilbert matrix.

A = sym(invhilb(5))
H = hermiteForm(A)
A =
[    25,   -300,    1050,   -1400,    630]
[  -300,   4800,  -18900,   26880, -12600]
[  1050, -18900,   79380, -117600,  56700]
[ -1400,  26880, -117600,  179200, -88200]
[   630, -12600,   56700,  -88200,  44100]

H =
[ 5,  0, -210, -280,  630]
[ 0, 60,    0,    0,    0]
[ 0,  0,  420,    0,    0]
[ 0,  0,    0,  840,    0]
[ 0,  0,    0,    0, 2520]

### Hermite Form for Matrix of Univariate Polynomials

Create a 2-by-2 matrix, the elements of which are polynomials in the variable x.

syms x
A = [x^2 + 3, (2*x - 1)^2; (x + 2)^2, 3*x^2 + 5]
A =
[   x^2 + 3, (2*x - 1)^2]
[ (x + 2)^2,   3*x^2 + 5]

Find the Hermite form of this matrix.

H = hermiteForm(A)
H =
[ 1, (4*x^3)/49 + (47*x^2)/49 - (76*x)/49 + 20/49]
[ 0,            x^4 + 12*x^3 - 13*x^2 - 12*x - 11]

### Hermite Form for Matrix of Multivariate Polynomials

Create a 2-by-2 matrix that contains two variables: x and y.

syms x y
A = [2/x + y, x^2 - y^2; 3*sin(x) + y, x]
A =
[      y + 2/x, x^2 - y^2]
[ y + 3*sin(x),         x]

Find the Hermite form of this matrix. If you do not specify the polynomial variable, hermiteForm uses symvar(A,1) and thus determines that the polynomial variable is x. Because 3*sin(x) + y is not a polynomial in x, hermiteForm throws an error.

H = hermiteForm(A)
Cannot convert the matrix entries to integers or univariate polynomials.

Find the Hermite form of A specifying that all elements of A are polynomials in the variable y.

H = hermiteForm(A,y)
H =
[ 1, (x*y^2)/(3*x*sin(x) - 2) + (x*(x - x^2))/(3*x*sin(x) - 2)]
[ 0,     3*y^2*sin(x) - 3*x^2*sin(x) + y^3 + y*(- x^2 + x) + 2]

### Hermite Form and Transformation Matrix

Find the Hermite form and the corresponding transformation matrix for an inverse Hilbert matrix.

A = sym(invhilb(3));
[U,H] = hermiteForm(A)
U =
[ 13,  9,  7]
[  6,  4,  3]
[ 20, 15, 12]

H =
[ 3,  0, 30]
[ 0, 12,  0]
[ 0,  0, 60]

Verify that H = U*A.

isAlways(H == U*A)
ans =
3×3 logical array
1     1     1
1     1     1
1     1     1

Find the Hermite form and the corresponding transformation matrix for a matrix of polynomials.

syms x y
A = [2*(x - y), 3*(x^2 - y^2);
4*(x^3 - y^3), 5*(x^4 - y^4)];
[U,H] = hermiteForm(A,x)
U =
[                   1/2,  0]
[ 2*x^2 + 2*x*y + 2*y^2, -1]

H =
[ x - y,         (3*x^2)/2 - (3*y^2)/2]
[     0, x^4 + 6*x^3*y - 6*x*y^3 - y^4]

Verify that H = U*A.

isAlways(H == U*A)
ans =
2×2 logical array
1     1
1     1

### If You Specify Variable for Integer Matrix

If a matrix does not contain a particular variable, and you call hermiteForm specifying that variable as the second argument, then the result differs from what you get without specifying that variable. For example, create a matrix that does not contain any variables.

A = [9 -36 30; -36 192 -180; 30 -180 180]
A =
9   -36    30
-36   192  -180
30  -180   180

Call hermiteForm specifying variable x as the second argument. In this case, hermiteForm assumes that the elements of A are univariate polynomials in x.

syms x
hermiteForm(A,x)
ans =
1     0     0
0     1     0
0     0     1

Call hermiteForm without specifying variables. In this case, hermiteForm treats A as a matrix of integers.

hermiteForm(A)
ans =
3     0    30
0    12     0
0     0    60

## Input Arguments

collapse all

Input matrix, specified as a symbolic matrix, the elements of which are integers or univariate polynomials. If the elements of A contain more than one variable, use the var argument to specify a polynomial variable, and treat all other variables as symbolic parameters. If A is multivariate, and you do not specify var, then hermiteForm uses symvar(A,1) to determine a polynomial variable.

Polynomial variable, specified as a symbolic variable.

## Output Arguments

collapse all

Hermite normal form of input matrix, returned as a symbolic matrix. The Hermite form of a matrix is an upper triangular matrix.

Transformation matrix, returned as a unimodular symbolic matrix. If elements of A are integers, then elements of U are also integers, and det(U) = 1 or det(U) = -1. If elements of A are polynomials, then elements of U are univariate polynomials, and det(U) is a constant.

collapse all

### Hermite Normal Form

For any square n-by-n matrix A with integer coefficients, there exists an n-by-n matrix H and an n-by-n unimodular matrix U, such that A*U = H, where H is the Hermite normal form of A. A unimodular matrix is a real square matrix, such that its determinant equals 1 or -1. If A is a matrix of polynomials, then the determinant of U is a constant.

hermiteForm returns the Hermite normal form of a nonsingular integer square matrix A as an upper triangular matrix H, such that ${H}_{jj}\ge 0$ and $-\frac{{H}_{jj}}{2}<{H}_{ij}\le \frac{{H}_{jj}}{2}$ for $j>i$. If A is not a square matrix or a singular matrix, the matrix H is simply an upper triangular matrix.

Introduced in R2015b

## Support

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos