Smith form of matrix

returns
the Smith normal
form of a square invertible matrix `S`

= smithForm(`A`

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

`___ = smithForm(`

assumes
that the elements of `A`

,`var`

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

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]

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]

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]

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