Octave for Chapter 3
Examples in this section provide sample Octave code for answering questions about linear combinations, span, and linear independence. 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
We will use the following code.
% Let A_b1 and A_b2 be augmented matrices
% whose columns are the vectors of W
% together with vectors b1 and b2, respectively.
w1=[3; 6;-1; 0; 4];
w2=[1; -2; 3; 5; 1];
w3=[-1; 0; 4; -2; 3];
b1=[0; 4; 1; -1; 7];
b2=[-4; 26; -11; -41; 10];
A_b1=[w1 w2 w3 b1];
A_b2=[w1 w2 w3 b2];
% Reduced row-echelon form
rref_A_b1=rref(A_b1)
rref_A_b2=rref(A_b2)
The reduced row-echelon form of looks like this:
rref_A_b1 =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0
The row indicates that the system is infeasible, so cannot be written as a linear combination of vectors in .
The reduced row-echelon form of looks like this:
rref_A_b2 =This shows that the system of equations has a solution: , , . We write,
1 0 0 2
0 1 0 -7
0 0 1 3
0 0 0 0
0 0 0 0
% Define the vectors individually
w1=[38; 15; -11];
w2=[64; 82; 14];
w3=[-3; 13; 9];
A=[w1 w2 w3];
% Reduced row-echelon form
rref_A=rref(A)
We get the following output
rref_A =We can see that there are infinitely many solutions , , . Letting , we write, Since (eq:oct_lin_comb) has a non-trivial solution, we conclude that the vectors are linearly dependent.
1 0 -0.5
0 1 0.25
0 0 0
% Define the vectors individually
w1=[12; 10; -20; 5];
w2=[3; -14; 21; 11];
w3=[-6; -38; 62; 17];
w4=[4; -4; 23; 19];
w5=[-6; 6; 47; 30];
w6=[2; 11; 17; 8];
% Clearly {w1} is linearly independent
% Let’s add w2 to the set and check.
rref([w1 w2]) % Looks like w1 and w2 are linearly independent
rref([w1 w2 w3]) % w3 is redundant - this set is linearly dependent. We won’t add w3 to the set
rref([w1 w2 w4]) % these are linearly independent
rref([w1 w2 w4 w5]) % w5 is redundant; don’t add
rref([w1 w2 w4 w6])
By starting with , adding vectors to our set one at a time, and checking for linear independence, we determined that and are redundant and can be removed from the set without changing the span.
Octave Exercises
- (a)
-
is in . is NOT in .
- (b)
-
is in . is NOT in .