You are about to erase your work on this activity. Are you sure you want to do this?
Updated Version Available
There is an updated version of this activity. If you update to the most recent version of this activity, then your current progress on this activity will be erased. Regardless, your record of completion will remain. How would you like to proceed?
Mathematical Expression Editor
Octave for Chapter 7
Examples in this section provide sample Octave code for finding determinants and
illustrating their uses and properties. You can access our code through the link at the
bottom of each template. Feel free to modify the code and experiment to learn
more!
You can write your own code using Octave software or online Octave cells. To access
Octave cells online, go to the Sage Math Cell Webpage, select OCTAVE as the
language, enter your code, and press EVALUATE.
To ”save” or share your online code, click on the Share button, select Permalink,
then copy the address directly from the browser window. You can store this link to
access your work later or share this link with others. You will need to get a new
Permalink every time you modify the code.
Octave Tutorial
In practice, computing determinants using Laplace Expansion is computationally
expensive. -factorization can be used to improve efficiency, but may be numerically
unstable. As a result, determinants are rarely used in computational practice.
Examples and exercises in this section are designed to illustrate theoretical properties
and computational pitfalls associated with determinants and should not be
interpreted as templates for large-scale computational problems.
We will use the det function to find determinants in Octave.
Compute the determinant of each of the following matrices. If a matrix is singular,
say so.
We find the determinant of each matrix.
% Define matrices A and B
A=[-1 5 -1;
7 -4 -1;
5 6 -3];
B=[6 -1 2;
12 -3 1;
-1 4 11];
% Find det(A) and det(B)
det_A=det(A)
det_B=det(B)
We see that and . We conclude that is singular and is not.
The following example illustrates a common technique for computing determinants
numerically.
In Exploration init:LUfactorization, we found that
Having a lower triangular/upper triangular factorization makes it easy to compute
the determinant. Find the determinant of by sight.
Unfortunately, -factorization is prone to round-off error, which may lead to erroneous
or ambiguous outcomes, as you will see Problem prob_oct_det1.
For our next example, recall the following theorem, known as Cramer’s Rule.
th:cramer Let be a nonsingular matrix, and let be an vector. Then the components of the
solution vector of are given by
where is matrix with its column replaced by .
Use Octave to solve the following system for using Cramer’s rule.
We will use the following code.
% Define columns of matrix A
c_1=[1; -1; 0];
c_2=[2; 1; 3];
c_3=[-1; 1; 1];
% Combine the columns to form matrix A
A=[c_1 c_2 c_3];
% Define vector b
b=[-2; 3; 1];
% Form A_1 by replacing the first column of A with b
A_1=[b c_2 c_3];
Determine whether each of the above matrices is singular in two different ways.
Use the det function
Use an alternative approach
Are the two methods used above in agreement? Click the arrow on the right to learn
more.
Octave uses -decomposition to compute the determinant. This method is susceptible
to rounding errors (Reference). Because of this, using the det function to determine
singularity is generally not a good idea.
If is non-singular, find , and . Illustrate the relationship between and
computationally.
Modify Example ex_det_prop to illustrate parts (a) and (c) of Theorem th:elemrowopsanddet. (Use rows and
coefficients of your choice.)