<jupyter_start><jupyter_text>+ This notebook is part of lecture 10 *The four fundamental subspaces* in the OCW MIT course 18.06 by Prof <NAME> [1]+ Created by me, Dr <NAME>    + Head of Acute Care Surgery    + Groote Schuur Hospital    + University Cape Town    + Email me with your thoughts, comments, suggestions and corrections Linear Algebra OCW MIT18.06 IPython notebook [2] study notes by Dr <NAME> is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.+ [1] OCW MIT 18.06+ [2] <NAME>, <NAME>, IPython: A System for Interactive Scientific Computing, Computing in Science and Engineering, vol. 9, no. 3, pp. 21-29, May/June 2007, doi:10.1109/MCSE.2007.53. URL: http://ipython.org<jupyter_code>from IPython.core.display import HTML, Image
css_file = 'style.css'
HTML(open(css_file, 'r').read())
#import numpy as np
from sympy import init_printing, Matrix, symbols
#import matplotlib.pyplot as plt
#import seaborn as sns
#from IPython.display import Image
from warnings import filterwarnings

init_printing(use_latex = 'mathjax') # Pretty Latex printing to the screen
#%matplotlib inline
filterwarnings('ignore')<jupyter_output><empty_output><jupyter_text>The four fundamental subspaces Introducing the matrix space  The four fundamental subspaces * Columnspace, C(A)* Nullspace, N(A)* Rowspaces    * All linear combinations of rows    * All the linear combinations of the colums of AT, C(AT)* Nullspace of AT, N(AT) (the left nullspace of A)  Where are these spaces for a matrix Am&215;n? * C(A) is in &8477;m* N(A) is in &8477;n* C(AT) is in &8477;n* N(AT) is in &8477;m  Calculating basis and dimension  For C(A) * The bases are the pivot columns* The dimension is the rank *r*  For N(A) * The bases are the special solutions (one for every free variable, *n* - *r*)* The dimension is *n* - *r*  For C(AT) * If A undergoes row reduction to row echelon form (R), then C(R) &8800; C(A), but rowspace(R) = rowspace(A) (or C(RT) = C(AT))* A basis for the rowspace of A (or R) is the first *r* rows of R    * So we row reduce A and take the pivot rows and transpose them* The dimension is also equal to the rank *r*  For N(AT) * It is also called the left, because it ends up on the left (as seen below)* Here we have AT**y** = **0**    * **y**T(AT)T = **0**T    * **y**TA = **0**T    * This is (again) the pivot columns of AT (after row reduction)* The dimension is *m* - *r*  Example problems  Consider this example matrix and calculate the bases and dimension for all four fundamental spaces<jupyter_code>A = Matrix([[1, 2, 3, 1], [1, 1, 2, 1], [1, 2, 3, 1]]) # We note that rows 1 and three are identical and that
# columns 3 is the addtion of columns 1 and 2 and column 1 equals column 4
A<jupyter_output><empty_output><jupyter_text>Columnspace<jupyter_code>A.rref() # Remember that the columnspace contains the pivot columns as a basis<jupyter_output><empty_output><jupyter_text>* The basis is thus:$$ \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 0 & 0 \end{bmatrix} $$* It is indeed in &8477;3 (rows of A = *m* = 3, i.e. each column vector is in 3-space or has 3 components) * The rank (no of columns with pivots) are 2, thus dim(A) = 2  Nullspace<jupyter_code>A.nullspace() # Calculating the nullspace vectors<jupyter_output><empty_output><jupyter_text>* So, indeed the basis is in &8477;4 (A has *n* = 4 columns)<jupyter_code>A.rref() # No pivots for columns 3 and 4<jupyter_output><empty_output><jupyter_text>* The dimension is two (there are 2 column vectors, which is indeed *n* - *r* = 4 - 2 = 2)  Rowspace C(AT) * So we are looking for the pivot columns of AT<jupyter_code>A.rref()<jupyter_output><empty_output><jupyter_text>* The pivot rows are rows 1 and 2* We take them and transpose them$$ \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \\ 1 & 0 \end{bmatrix} $$ * As stated above, it is in &8477;4 * The dimension is *n* - *r* = 4 - 2 = 2  Nullspace of AT<jupyter_code>A.nullspace()<jupyter_output><empty_output><jupyter_text>* Which is indeed in &8477;3 * The dimension is 1, since *m* - *r* = 3 - 2 = 1 (remember that the rank is the number of pivot columns)  Consider this example matrix (in LU form) and calculate the bases and dimension for all four fundamental spaces<jupyter_code>L = Matrix([[1, 0, 0], [2, 1, 0], [-1, 0, 1]])
U = Matrix([[5, 0, 3], [0, 1, 1], [0, 0, 0]])
A = L * U
L, U, A<jupyter_output><empty_output><jupyter_text>Columnspace of A<jupyter_code>A.rref()<jupyter_output><empty_output><jupyter_text>* The basis is thus:$$ \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 0 & 0 \end{bmatrix} $$* Another basis would be the pivot columns of L:$$ \begin{bmatrix} 1 & 0 \\ 2 & 1 \\ -1 & 0 \end{bmatrix} $$* It is in &8477;3, since *m* = 3* It has a rank of 2 (two pivot columns)* Since the dimension of the columnspace is equal to the rank, dim(A) = 2    * Note that it is also equal to the number of pivot columns in U  Nullspace of A<jupyter_code>A.nullspace()<jupyter_output><empty_output><jupyter_text>* The nullspace is in &8477;3, since *n* = 3* The basis is the special solution(s), which is one column vector for every free variable    * Since we only have a single free variable, we have a single nullspace column vector    * This fits in with the fact that it needs to be *n* - *r*    * It can also be calculated by taking U, setting the free variable to 1 and solving for the other rows by setting each equal to zero* The dimension of the nullspace is also 1 (*n* - *r*, i.e. a single column)    * It is also the number of free variables  The rowspace * This is the columnspace of AT* Don't take the transpose first!* Row reduce, identify the rows with pivots and transpose them<jupyter_code>A.rref()<jupyter_output><empty_output><jupyter_text>* The basis is can also be written down by identifying the rows with pivots in U and writing them down as columns (getting their transpose)$$ \begin{bmatrix} 5 & 0 \\ 0 & 1 \\ 3 & 1 \end{bmatrix} $$* It is in &8477;3, since *n* = 3* The rank *r* = 2, which is equal to the dimension, i.e. dim(AT) = 2  The nullspace of AT<jupyter_code>A.transpose().nullspace()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11384918679152292, 'fraction_numerical': 0.03302119270576639, 'mean_word_length': 4.368606701940036, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '300837', 'license': 'MIT', 'n_tokens_mistral': 2185, 'n_tokens_neox': 1993, 'n_words': 881, 'path': '_math/MIT_OCW_18_06_Linear_algebra/I_11_Subspaces.ipynb', 'repo_name': 'aixpact/data-science', 'size': '6129'}