Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
Kernel:
%%html <link href="https://pretextbook.org/beta/mathbook-content.css" rel="stylesheet" type="text/css" /> <link href="https://aimath.org/mathbook/mathbook-add-on.css" rel="stylesheet" type="text/css" /> <style>.subtitle {font-size:medium; display:block}</style> <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic" rel="stylesheet" type="text/css" /> <link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700&subset=latin,latin-ext" rel="stylesheet" type="text/css" /><!-- Hide this cell. --> <script> var cell = $(".container .cell").eq(0), ia = cell.find(".input_area") if (cell.find(".toggle-button").length == 0) { ia.after( $('<button class="toggle-button">Toggle hidden code</button>').click( function (){ ia.toggle() } ) ) ia.hide() } </script>

Important: to view this notebook properly you will need to execute the cell above, which assumes you have an Internet connection. It should already be selected, or place your cursor anywhere above to select. Then press the "Run" button in the menu bar above (the right-pointing arrowhead), or press Shift-Enter on your keyboard.

ParseError: KaTeX parse error: \newcommand{\lt} attempting to redefine \lt; use \renewcommand

Sage and Linear Algebra Worksheet: FCLA Section B

Robert Beezer
Department of Mathematics and Computer Science
University of Puget Sound
Fall 2019
Section 1 Bases

Five “random” vectors, each with 4 entries, collected into a set S.

v1 = vector(QQ, [-4, -2, 3, -11]) v2 = vector(QQ, [-2, 7, 3, 9]) v3 = vector(QQ, [ 6, -4, -7, 5]) v4 = vector(QQ, [-1, 0, 3, -4]) v5 = vector(QQ, [-4, 5, -5, 11]) S = [v1, v2, v3, v4, v5]

Consider the subspace spanned by these five vectors. We will make these vectors the rows of a matrix and row-reduce to see a basis for the space (subspace, or row space, take your pick). This is an application of Theorem BRS.

A = matrix(S) A
A.rref()

Sage does this semi-automatically, tossing zero rows for us.

W = span(S) B = W.basis() B
Demonstration 1.

Construct a random vector, w, in this subspace by choosing scalars for a linear combination of the vectors we used to build W as a span originally.

Then use the three basis vectors in B to recreate the vector w. Question: how many ways can you do this? By Theorem VRRB there should always be exactly one way to create w using a linear combination of a basis of W.

w = *v1 + *v2 + *v3 + *v4 + *v5 w
w in W
*B[0] + *B[1] + *B[2]
Section 2 Nonsingular Matrices

We will obtain a basis of C10\mathbb{C}^{10} from the columns of a 10Ă—1010\times 10 nonsingular matrix.

entries = [[ 1, 1, 1, -1, -2, 4, 2, -3, 1, -6], [-2, -1, -2, 2, 4, -7, -4, 5, -1, 7], [ 1, -1, 2, -2, -5, 8, 5, -3, 4, -4], [-1, -2, 0, 1, 0, -5, 0, -3, -5, 6], [ 0, -2, 1, -1, -2, 3, 2, 3, 3, 7], [ 1, 0, 1, -1, -2, 4, 2, 0, 2, 0], [-1, 0, -1, 1, 3, -1, -2, 7, 5, 1], [ 1, 1, 1, -1, -2, 8, 3, 2, 8, -6], [ 0, 2, -1, 1, 2, -1, -2, 2, 2, -6], [ 1, 3, 0, 0, 1, 3, 0, 0, 3, -8]] M = matrix(QQ, entries) M
not M.is_singular()

A totally random vector with 10 entries:

v = random_vector(ZZ, 10, x=-9, y=9) v
Demonstration 2.

By Theorem CNMB, the columns of the matrix are a basis of C10.\mathbb{C}^{10}\text{.} So the vector v should be a linear combination of the columns of the matrix. Verify this fact in three ways.

  1. First, the old-fashioned way, thus exposing Theorem NMUS.
  2. Then, the modern way, with an inverse, since a nonsingular matrix is invertible, thus exposing Theorem SNCM.
  3. Finally, the Sage way, as described below.
aug = M.augment(v) aug.rref()
M.inverse()*v

The Sage way: first create a space with a .

X = (QQ^10).subspace_with_basis(M.columns()) X

Sage still carries an , in addition to the basis.

X.basis()
X.echelonized_basis()

Now ask for a coordinatization, relative to the basis in X, thus exposing Theorem VRRB.

X.coordinates(v)
Section 3 Orthonormal Bases

A particularly simple orthonormal basis of C3,\mathbb{C}^3\text{,} collected into the set S.

v1 = vector(QQ, [1/3, 2/3, 2/3]) v2 = vector(QQ, [2/3, -2/3, 1/3]) v3 = vector(QQ, [2/3, 1/3, -2/3]) S = [v1, v2, v3]
Demonstration 3.

If these vectors are an orthonormal basis, then as the columns of a matrix they should create an orthonormal basis.

Q = column_matrix(S) Q
Q.conjugate_transpose()*Q
Q.is_unitary()
Demonstration 4.

Build a random vector of size 33 and find our ways to express the vector as a (unique) linear combination of the basis vectors. Which method is most efficient?

A totally random vector with 3 entries.

v = random_vector(ZZ, 3, x=-9, y=9) v

First, the old-fashioned way, thus exposing Theorem NMUS.

aug = Q.augment(v) aug.rref()

Now, the modern way, with an inverse, since a nonsingular matrix is invertible, thus exposing Theorem SNCM.

Q.inverse()*v

The Sage way. Create a space with a “user basis” and ask for a coordinatization, thus exposing Theorem VRRB.

X = (QQ^3).subspace_with_basis(Q.columns()) X.coordinates(v)

Finally, exploiting the orthonormal basis, and computing scalars for the linear combination with an inner product, thus exposing Theorem COB. (Sage's .inner\_product() does not conjugate the entries of either vector, so we use the more careful .hermitian\_inner\_product() vector method instead.)

a1 = v1.hermitian_inner_product(v) a2 = v2.hermitian_inner_product(v) a3 = v3.hermitian_inner_product(v) a1, a2, a3

This work is Copyright 2016–2019 by Robert A. Beezer. It is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.