Octave- Verberg vooruitgang Hide progress Toon vooruitgang Show progress
- Verwijder je antwoorden (op deze pagina) Remove your answers (on this page)
OctaveThe templates in this section provide sample Octave code for finding subspaces associated with matrices as well as the kernel and image of a linear transformation. 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.
Recall that the column space of a matrix is the span of the columns of the matrix. In Subspaces of \(\RR ^n\) Associated with Matrices we introduced the following procedure for finding the column space.
We will implement this procedure in Octave.
We can find the reduced row-echelon form of \(A\) using the rref function, and identify the pivot columns visually. We can also take advantage of the expanded version of the rref function to identify the pivot columns automatically, as shown below.
% Define A
A = [2 -1 1 -4 1;
1 0 3 3 0;
-2 1 -1 5 2;
4 -1 7 2 1];
% Compute rref of A
[rref_A, pivot_cols] = rref(A);
% the pivot column indices are...
pivot_cols
% Extract the pivot columns from A, using pivot column indices
colSpace_basis = A(:, pivot_cols)
When you study linear transformations, you will learn that the column space of a matrix is the image of the linear transformation induced by the matrix. So, Template 2 can be used to find the image of a linear transformation.
Recall the following definition of the null space of a matrix from Subspaces of \(\RR ^n\) Associated with Matrices.
We can use the reduced row-echelon form (rref function) to find the null space, as shown in Example ?? of Subspaces of \(\RR ^n\) Associated with Matrices. We will omit the details here.
We can also use the null function to find a basis for the null space of a matrix. This function finds an orthonormal basis for the null space. An orthonormal set of vectors consists of unit vectors that are pairwise orthogonal. We demonstrate the null function below.
% Define A
A = [2 -1 1 -4 1;
1 0 3 3 0;
-2 1 -1 5 2;
4 -1 7 2 1];
% Basis for null(A)
% Octave constructs an orthonormal basis, meaning that the basis elements are pairwise orthogonal unit vectors.
B=null(A)
% To find the dimension of the null space, find the number of columns in B
[rows, cols]=size(B)
The basis for the null space we found in Template 4 looks different from what you would have found by hand using the rref function. In Problem you will verify that \(B\) in Template 4 spans the null space of \(A\).
If you are familiar with linear transformations, you may recall that the kernel of a linear transformation induced by a matrix is the null space of the matrix. The null function gives us a way to compute the kernel.
For Problems and , use Octave to find \(\text {col}(A)\), \(\text {null}(A)\), and their respective dimensions. Verify that the Rank-Nullity Theorem (??) holds for \(A\).
% Find a basis for row(A) and column(A)
A=[1 3 0 -2 0 3;
3 9 1 -7 0 8;
1 3 1 -3 1 -1;
1 3 -1 -1 -2 10]
% We can answer all of these questions by finding rref(A).
rref(A)
Matrices used in Problems - come from the end of Chapter 4 of Ken Kuttler’s A First Course in Linear Algebra. (CC-BY)
Ken Kuttler, A First Course in Linear Algebra, Lyryx 2017, Open Edition, pp. 227–232.