Documentation

smithForm

Smith form of matrix

Description

example

S = smithForm(A) returns the Smith normal form of a square invertible matrix A. The elements of A must be integers or polynomials in a variable determined by symvar(A,1). The Smith form S is a diagonal matrix.

example

[U,V,S] = smithForm(A) returns the Smith normal form of A and unimodular transformation matrices U and V, such that S = U*A*V.

example

___ = smithForm(A,var) assumes that the elements of A are univariate polynomials in the specified variable var. If A contains other variables, smithForm 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 smithForm(A) and smithForm(A,var) return different results.

Examples

Smith Form for Matrix of Integers

Find the Smith form of an inverse Hilbert matrix.

A = sym(invhilb(5))
S = smithForm(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]

S =
[ 5,  0,   0,   0,    0]
[ 0, 60,   0,   0,    0]
[ 0,  0, 420,   0,    0]
[ 0,  0,   0, 840,    0]
[ 0,  0,   0,   0, 2520]

Smith 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 Smith form of this matrix.

S = smithForm(A)
S =
[ 1,                                 0]
[ 0, x^4 + 12*x^3 - 13*x^2 - 12*x - 11]

Smith Form for Matrix of Multivariate Polynomials

Create a 2-by-2 matrix containing 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 Smith form of this matrix. If you do not specify the polynomial variable, smithForm uses symvar(A,1) and thus determines that the polynomial variable is x. Because 3*sin(x) + y is not a polynomial in x, smithForm throws an error.

S = smithForm(A)
Error using mupadengine/feval (line 163)
Cannot convert the matrix entries to integers or univariate polynomials.

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

S = smithForm(A,y)
S =
[ 1,                                                     0]
[ 0, 3*y^2*sin(x) - 3*x^2*sin(x) + y^3 + y*(- x^2 + x) + 2]

Smith Form and Transformation Matrices

Find the Smith form and transformation matrices for an inverse Hilbert matrix.

A = sym(invhilb(3));
[U,V,S] = smithForm(A)
U =
[  1,  1, 1]
[ -4, -1, 0]
[ 10,  5, 3]

V =
[ 1, -2, 0]
[ 0,  1, 5]
[ 0,  1, 4]

S =
[ 3,  0,  0]
[ 0, 12,  0]
[ 0,  0, 60]

Verify that S = U*A*V.

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

Find the Smith form and transformation matrices 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,V,S] = smithForm(A,x)
U =
[ 0,                        1]
[ 1, - x/(10*y^3) - 3/(5*y^2)]

V =
[ -x/(4*y^3), - (5*x*y^2)/2 - (5*x^2*y)/2 - (5*x^3)/2 - (5*y^3)/2]
[  1/(5*y^3),                               2*x^2 + 2*x*y + 2*y^2]

S =
[ x - y,                             0]
[     0, x^4 + 6*x^3*y - 6*x*y^3 - y^4]

Verify that S = U*A*V.

isAlways(S == U*A*V)
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 smithForm 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 smithForm specifying variable x as the second argument. In this case, smithForm assumes that the elements of A are univariate polynomials in x.

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

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

smithForm(A)
ans =
3     0     0
0    12     0
0     0    60

Input Arguments

collapse all

Input matrix, specified as a square invertible 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 smithForm uses symvar(A,1) to determine a polynomial variable.

Polynomial variable, specified as a symbolic variable.

Output Arguments

collapse all

Smith normal form of input matrix, returned as a symbolic diagonal matrix. The first diagonal element divides the second, the second divides the third, and so on.

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.

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

collapse all

Smith Normal Form

Smith normal form of a an n-by-n matrix A is an n-by-n diagonal matrix S, such that ${S}_{i,\text{\hspace{0.17em}}i}$ divides ${S}_{i+1,\text{\hspace{0.17em}}i+1}$ for all i < n.