Symbolic Math Toolbox    

Linear Algebraic Operations

The following examples show to do several basic linear algebraic operations using the Symbolic Math Toolbox.

The command

generates the 3-by-3 Hilbert matrix. With format short, MATLAB prints

The computed elements of H are floating-point numbers that are the ratios of small integers. Indeed, H is a MATLAB array of class double. Converting H to a symbolic matrix

gives

This allows subsequent symbolic operations on H to produce results that correspond to the infinitely precise Hilbert matrix, sym(hilb(3)), not its floating-point approximation, hilb(3). Therefore,

produces

and

yields

You can use the backslash operator to solve a system of simultaneous linear equations. For example, the commands

produce the solution

All three of these results, the inverse, the determinant, and the solution to the linear system, are the exact results corresponding to the infinitely precise, rational, Hilbert matrix. On the other hand, using digits(16), the command

returns

The decimal points in the representation of the individual elements are the signal to use variable-precision arithmetic. The result of each arithmetic operation is rounded to 16 significant decimal digits. When inverting the matrix, these errors are magnified by the matrix condition number, which for hilb(3) is about 500. Consequently,

which returns

shows the loss of two digits. So does

which gives

and

which is

Since H is nonsingular, calculating the null space of H with the command

returns an empty matrix, and calculating the column space of H with

returns a permutation of the identity matrix. A more interesting example, which the following code shows, is to find a value s for H(1,1) that makes H singular. The commands

produce

Then

substitutes the computed value of sol for s in H to give

Now, the command

returns

and

produces an error message

because H is singular. For this matrix, Z = null(H) and C = colspace(H) are nontrivial:

It should be pointed out that even though H is singular, vpa(H) is not. For any integer value d, setting

and then computing

results in a determinant of size 10^(-d) and an inverse with elements on the order of 10^d.


  Linear Algebra Eigenvalues 

Learn more about the latest releases of MathWorks products:

 © 1994-2010 The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS