Symbolic Matrix Computation
This example shows how to perform simple matrix computations using Symbolic Math Toolbox™.
Generate a possibly familiar test matrix, the 5-by-5 Hilbert matrix.
H =
The determinant is very small.
The elements of the inverse are integers.
X =
Verify that the inverse is correct.
I =
Find the characteristic polynomial.
p =
Try to factor the characteristic polynomial.
ans =
The result indicates that the characteristic polynomial cannot be factored over the rational numbers.
Compute the 50 digit numerical approximations to the eigenvalues.
e =
Create a generalized Hilbert matrix involving a free variable, .
H =
Substituting retrieves the original Hilbert matrix.
ans =
The reciprocal of the determinant is a polynomial in .
d =
d =
The elements of the inverse are also polynomials in .
X =
Substituting generates the Hilbert inverse.
X =
X = 5×5
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
Investigate a different example.
A =
This matrix is "nilpotent". Its fifth power is the zero matrix.
ans =
Because this matrix is nilpotent, its characteristic polynomial is very simple.
You should now be able to compute the matrix eigenvalues in your head. They are the zeros of the equation lambda^5 = 0.
Symbolic computation can find the eigenvalues exactly.
Numeric computation involves roundoff error and finds the zeros of an equation that is something like lambda^5 = eps*norm(A) So the computed eigenvalues are roughly lambda = (eps*norm(A))^(1/5) Here are the eigenvalues, computed by the Symbolic Toolbox using 16 digit floating point arithmetic. It is not obvious that they should all be zero.
lambda =
This matrix is also "defective". It is not similar to a diagonal matrix. Its Jordan Canonical Form is not diagonal.
J =
The matrix exponential, expm(t*A), is usually expressed in terms of scalar exponentials involving the eigenvalues, exp(lambda(i)*t). But for this matrix, the elements of expm(t*A) are all polynomials in t.
E =
By the way, the function "exp" computes element-by-element exponentials.
X =