I love working in the shell. Mastery of shell lets you get things done in seconds, rather than minutes or hours, if you chose to write a program instead.

In this article I'd like to explain the top one-liners from the commandlinefu.com. It's a user-driven website where people get to choose the best and most useful shell one-liners.

But before I do that, I want to take the opportunity and link to a few of my articles that I wrote some time ago on working efficiently in the command line:

- Working Efficiently in Bash (Part I).
- Working Efficiently in Bash (Part II).
- The Definitive Guide to Bash Command Line History.
- A fun article on Set Operations in the Shell.
- Another fun article on Solving Google Treasure Hunt in the Shell.

**Update:** Russian translation now available.

And now the explanation of top one-liners from commandlinefu.

## #1. Run the last command as root

$ sudo !!

We all know what the `sudo`

command does - it runs the command as another user, in this case, it runs the command as superuser because no other user was specified. But what's really interesting is the bang-bang `!!`

part of the command. It's called the **event designator**. An event designator references a command in shell's history. In this case the event designator references the previous command. Writing `!!`

is the same as writing `!-1`

. The `-1`

refers to the last command. You can generalize it, and write `!-n`

to refer to the n-th previous command. To view all your previous commands, type `history`

.

This one-liner is actually really bash-specific, as event designators are a feature of bash.

I wrote about event designators in much more detail in my article "The Definitive Guide to Bash Command Line History." The article also comes with a printable cheat sheet for working with the history.

## #2. Serve the current directory at http://localhost:8000/

$ python -m SimpleHTTPServer

This one-liner starts a web server on port 8000 with the contents of current directory on all the interfaces (address 0.0.0.0), not just localhost. If you have "`index.html`

" or "`index.htm`

" files, it will serve those, otherwise it will list the contents of the currently working directory.

It works because python comes with a standard module called `SimpleHTTPServer`

. The `-m`

argument makes python to search for a module named `SimpleHTTPServer.py`

in all the possible system locations (listed in `sys.path`

and `$PYTHONPATH`

shell variable). Once found, it executes it as a script. If you look at the source code of this module, you'll find that this module tests if it's run as a script `if __name__ == '__main__'`

, and if it is, it runs the `test()`

method that makes it run a web server in the current directory.

To use a different port, specify it as the next argument:

$ python -m SimpleHTTPServer 8080

This command runs a HTTP server on all local interfaces on port 8080.

## #3. Save a file you edited in vim without the needed permissions

:w !sudo tee %

This happens to me way too often. I open a system config file in vim and edit it just to find out that I don't have permissions to save it. This one-liner saves the day. Instead of writing the while to a temporary file `:w /tmp/foobar`

and then moving the temporary file to the right destination `mv /tmp/foobar /etc/service.conf`

, you now just type the one-liner above in vim and it will save the file.

Here is how it works, if you look at the vim documentation (by typing `:he :w`

in vim), you'll find the reference to the command `:w !{cmd}`

that says that vim runs `{cmd}`

and passes it the contents of the file as standard input. In this one-liner the `{cmd}`

part is the `sudo tee %`

command. It runs `tee %`

as superuser. But wait, what is `%`

? Well, it's a read-only register in vim that contains the filename of the current file! Therefore the command that vim executes becomes `tee current_filename`

, with the current directory being whatever the `current_file`

is in. Now what does `tee`

do? The `tee`

command takes standard input and write it to a file! Rephrasing, it takes the contents of the file edited in vim, and writes it to the file (while being root)! All done!

## #4. Change to the previous working directory

$ cd -

Everyone knows this, right? The dash "`-`

" is short for "previous working directory." The previous working directory is defined by `$OLDPWD`

shell variable. After you use the `cd`

command, it sets the `$OLDPWD`

environment variable, and then, if you type the short version `cd -`

, it effectively becomes `cd $OLDPWD`

and changes to the previous directory.

To change to a directory named "`-`

", you have to either cd to the parent directory and then do `cd ./-`

or do `cd /full/path/to/-`

.

## #5. Run the previous shell command but replace string "foo" with "bar"

$ ^foo^bar^

This is another event designator. This one is for quick substitution. It replaces `foo`

with `bar`

and repeats the last command. It's actually a shortcut for `!!:s/foo/bar/`

. This one-liner applies the `s`

modifier to the `!!`

event designator. As we learned from one-liner #1, the `!!`

event designator stands for the previous command. Now the `s`

modifier stands for substitute (greetings to sed) and it substitutes the first word with the second word.

Note that this one-liner replaces just the first word in the previous command. To replace all words, add the `g`

modifer (`g`

for global):

$ !!:gs/foo/bar

This one-liner is also bash-specific, as event designators are a feature of bash.

Again, see my article "The Definitive Guide to Bash Command Line History." I explain all this stuff in great detail.

## #6. Quickly backup or copy a file

$ cp filename{,.bak}

This one-liner copies the file named `filename`

to a file named `filename.bak`

. Here is how it works. It uses **brace expansion** to construct a list of arguments for the `cp`

command. Brace expansion is a mechanism by which arbitrary strings may be generated. In this one-liner `filename{,.bak}`

gets brace expanded to `filename filename.bak`

and puts in place of the brace expression. The command becomes `cp filename filename.bak`

and file gets copied.

Talking more about brace expansion, you can do all kinds of combinatorics with it. Here is a fun application:

$ echo {a,b,c}{a,b,c}{a,b,c}

It generates all the possible strings 3-letter from the set `{a, b, c}`

:

aaa aab aac aba abb abc aca acb acc baa bab bac bba bbb bbc bca bcb bcc caa cab cac cba cbb cbc cca ccb ccc

And here is how to generate all the possible 2-letter strings from the set of `{a, b, c}`

:

$ echo {a,b,c}{a,b,c}

It produces:

aa ab ac ba bb bc ca cb cc

If you liked this, you may also like my article where I defined a bunch of set operations (such as intersection, union, symmetry, powerset, etc) by using just shell commands. The article is called "Set Operations in the Unix Shell." (And since I have sets in the shell, I will soon write articles on on "**Combinatorics in the Shell**" and "**Algebra in the Shell**". Fun topics to explore. Perhaps even "Topology in the Shell" :))

## #7. mtr - traceroute and ping combined

$ mtr google.com

MTR, bettern known as "Matt's Traceroute" combines both `traceroute`

and `ping`

command. After each successful hop, it sends a ping request to the found machine, this way it produces output of both `traceroute`

and `ping`

to better understand the quality of link. If it finds out a packet took an alternative route, it displays it, and by default it keeps updating the statistics so you knew what was going on in real time.

## #8. Find the last command that begins with "whatever," but avoid running it

$ !whatever:p

Another use of event designators. The `!whatever`

designator searches the shell history for the most recently executed command that starts with `whatever`

. But instead of executing it, it prints it. The `:p`

modifier makes it print instead of executing.

This one-liner is bash-specific, as event designators are a feature of bash.

Once again, see my article "The Definitive Guide to Bash Command Line History." I explain all this stuff in great detail.

## #9. Copy your public-key to remote-machine for public-key authentication

$ ssh-copy-id remote-machine

This one-liner copies your public-key, that you generated with `ssh-keygen`

(either SSHv1 file identity.pub or SSHv2 file id_rsa.pub) to the `remote-machine`

and places it in `~/.ssh/authorized_keys`

file. This ensures that the next time you try to log into that machine, public-key authentication (commonly referred to as "passwordless authentication.") will be used instead of the regular password authentication.

If you wished to do it yourself, you'd have to take the following steps:

your-machine$ scp ~/.ssh/identity.pub remote-machine: your-machine$ ssh remote-machine remote-machine$ cat identity.pub >> ~/.ssh/authorized_keys

This one-liner saves a great deal of typing. Actually I just found out that there was a shorter way to do it:

your-machine$ ssh remote-machine 'cat >> .ssh/authorized_keys' < .ssh/identity.pub

## #10. Capture video of a linux desktop

$ ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg

A pure coincidence, I have done so much video processing with ffmpeg that I know what most of this command does without looking much in the manual.

The ffmpeg generally can be descibed as a command that takes a bunch of options and the last option is the output file. In this case the options are `-f x11grab -s wxga -r 25 -i :0.0 -sameq`

and the output file is `/tmp/out.mpg`

.

Here is what the options mean:

`-f x11grab`

makes ffmpeg to set the input video format as x11grab. The X11 framebuffer has a specific format it presents data in and it makes ffmpeg to decode it correctly.`-s wxga`

makes ffmpeg to set the size of the video to wxga which is shortcut for 1366x768. This is a strange resolution to use, I'd just write`-s 800x600`

.`-r 25`

sets the framerate of the video to 25fps.`-i :0.0`

sets the video input file to X11 display 0.0 at localhost.`-sameq`

preserves the quality of input stream. It's best to preserve the quality and post-process it later.

You can also specify ffmpeg to grab display from another x-server by changing the `-i :0.0`

to `-i host:0.0`

.

If you're interested in ffmpeg, here are my other articles on ffmpeg that I wrote while ago:

- How to Extract Audio Tracks from YouTube Videos
- Converting YouTube Flash Videos to a Better Format with ffmpeg

PS. This article was so fun to write, that I decided to write several more parts. Tune in the next time for "The Next Top Ten One-Liners from CommandLineFu Explained" :)

Have fun. See ya!

PSS. Follow me on twitter for updates.

## Sponsor this series!

Contact me, if you wish to sponsor any other of my existing posts or future posts!

Hey everyone, I'm starting a new article series here on catonmat that will be published on Fridays. It's called "**Visual Math Friday**." The goal of this article series is to assemble all the wonderful mathematical proofs and identities that can be proven in a single picture or drawing. I have been collecting them for years from various books, math journals, websites and video lectures and have collected several hundred of them.

If you have been following my blog, you'll have noticed that I love to explain things. I'll use the same writing style in this series as well. I'll post the visual proof together with my explanation. In the explanations I'll walk you through the proof, suggesting how to think about the visual image. But it's best if you try to understand the proof without reading my explanation and only then read it.

The proofs come from algebra, number theory, geometry, calculus, complex analysis, topology and various other fields of mathematics. I'll do one proof a week and will try to alternate between really easy, moderate and difficult proofs every week so that readers with various mathematical backgrounds can enjoy the series.

I'll start with a really easy integer sum proof this week. Without further ado, here it is.

Now try to figure what it proves without reading further! The colors play an important role in the visual proofs, as do the shape of the visual drawing, the shapes on it and their arrangement!

## The Proof

This picture proves that the sum of first n odd numbers is equal to n². In other words:

1 + 3 + 5 + 7 + 9 + 11 + ... + (2n-1) = n².

## Explanation

Imagine that the blue and green dots are marbles. Now let's look at the lower left corner. One blue marble is located there. Next if we follow the diagonal to the upper right corner, we see that the 1 blue marble is kind-of wrapped in 3 green marbles, then they in turn are wrapped in 5 blue marbles again, then those are wrapped in 7 green ones, which in turn are wrapped in 9 blue ones, then 11 green ones, and finally 13 ones.

This suggests that we could look at the sum 1 + 3 + 5 + 7 + 9 + 11 + 13. Well what is it? It's 49. Also what does this sum involve? It involves only odd numbers. Interesting.

Now let's count how many marbles we have on each side. 7 on one side and 7 on the other. And what is 7x7? It's 49! And how many numbers did we sum together? Well, seven - 1, 3, 5, 7, 9, 11, 13. Interesting.

Could it be that the sum of the first n odd numbers is equal to n²? Or in other words, is 1 + 3 + 5 + 7 + ... + (2n-1) equal to n²?

Let's try to prove this hypothesis by going one number further and adding 15 green marbles - 13 filled marbles and 2 semi-filled marbles:

Adding 15 marbles created a square of marbles again - now we have 64 marbles, 8 on each side.

The 2 semi-filled marbles are very important here. Each time we go further from n odd marbles to n+1 odd marbles, the difference changes by 2. This difference of two marbles can always be put where the semi-filled ones are in this picture.

This actually concludes the proof. We showed that the proof worked for several marbles, and showed how it still works if we went one step further. Therefore it works for all future steps. This method of proof is called mathematical induction and it's a very powerful and important tool in mathematics for proving sums like these.

## Before we go

Can you figure out the two proofs hidden in the logo of this post?

**Let me know in the comments if you can!**

## Get ahead of me

By the way, if you wish to get ahead of me in this series, you can get these three amazing books on visual proofs:

- Proofs Without Words I: Exercises in Visual Thinking.
- Proofs Without Words II: More Exercises in Visual Thinking.
- Math Made Visual.

Here are these books on Amazon.com:

**14**Comments March 03, 2010

# Vim Plugins You Should Know About, Part VII: ragtag.vim (formerly allml.vim)

This is the seventh post in the article series "**Vim Plugins You Should Know About**". This time I am going to introduce you to a plugin called "**ragtag.vim**". A month ago it was still known as "**allml.vim**" but now it has been renamed to **ragtag.vim**.

The best parts of RagTag are mappings for editing HTML tags. It has a mapping for quickly closing open HTML tags, a mapping for quickly turning the typed word into a pair of open/close HTML tags, several mappings for inserting HTML doctype, linking to CSS stylesheets, loading JavaScript `<script src="...">...</script>`

and it includes mappings for wrapping the typed text in a pair of `<?php ... ?>`

tags for PHP, or `<% ... %>`

for ASP or eRuby, and `{% .. %}`

for Django.

RagTag is written by **Tim Pope**. He's the master of Vim plugin programming. I have already written about two of his plugins - surround.vim and repeat.vim and more articles about his plugins are coming!

## Previous articles in the series.

- Part I: surround.vim - find and edit surrounding parens, quotes, html tags, etc.
- Part II: repeat.vim - repeat the previous surrounding command.
- Part III: matchit.vim - extends the functionality of % key.
- Part IV: snipmate.vim - the best snippet plugin for vim
- Part V: a.vim - quickly change between source and header files (.c/.h).
- Part VI: nerd_tree.vim - awesome filesystem exploration plugin.

Here are examples of using the RagTag plugin.

## Quickly closing an open HTML tag.

Suppose you have typed `<div>`

and you want to close it without typing the whole closing tag `</div>`

yourself.

The quick way to do it with RagTag is to press

. This mapping automatically closes the last open HTML tag.**CTRL+X /**

**Extra tip**: If you didn't have this plugin you could quickly close the tag by typing `</`

and pressing

. The default Vim mapping **CTRL+X CTRL+O**

guesses the item that may come after the cursor. In case of an open HTML tag it's the close tag.**CTRL+X CTRL+O**

## Creating a pair of open/close HTML tags from a word.

Suppose you want to quickly create a pair of `<div></div>`

and place the cursor between the two tags.

The quick way to do it with RagTag is to type `div`

and press

. This mapping takes the typed word and creates a pair of HTML tags, one closing tag and one open tag on the same line.**CTRL+X SPACE**

However, if you wish to create open/close tag pair separated by a newline, type

.**CTRL+X ENTER**

Here is an example, if you just typed `div`

and then press `CTRL+X ENTER`

it will produce the following output:

<div>|</div>

indicates the position of cursor.**|**

## Insert HTML doctype.

If you type

RagTag will display a list of HTML doctypes to choose from. Defaults to HTML 4.01 Strict.**CTRL+X !**

This mapping is not that useful, given that I already introduced snipmate.vim plugin for creating snippets. Using snipmate.vim you can create a snippet "h" that would insert the whole HTML structure, including doctype, html, body, title, meta tags, etc.

## Link to a CSS stylesheet.

Typing

inserts the snippet for linking to a CSS stylesheet.**CTRL+X @**

<link rel="stylesheet" type="text/css" href="/stylesheets/|.css">

This is again not that useful, given that we have snipmate.vim.

The mapping is easy to remember because `@`

is used for importing in CSS.

## Insert meta content-type tag.

Typing

inserts the HTML meta tag for document's content type and encoding.**CTRL+X #**

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

The charset depends on document's charset. If it's utf-8, the mapping will set the charset to utf-8 in the meta tag.

## Load JavaScript document.

Typing

links to a JavaScript file.**CTRL+X $**

<script type="text/javascript" src="/javascripts/|.js">

The mapping is easy to remember because `$`

is a valid char in identifiers in many languages.

## Wrap the typed text in PHP, Django, eRuby template tags.

There are several different mappings for wrapping text in template tags. It's best to summarize them in the following table. The table assumes you had just typed "foo" and you are editing an eRuby document:

Mapping Result --------- ----------- CTRL+X = foo<%=|%> CTRL+X + <%= foo|%> CTRL+X - foo<%|%> CTRL+X _ <% foo|%> CTRL+X ' foo<%#|%> CTRL+X " <%# foo|%>

What this table shows us is, for example, that if you have typed "foo" and press

, the plugin will wrap "foo" in **CTRL+X _**`<% %>`

tags and place the cursor after "foo".

## Summary of all the RagTag mappings.

CTRL+X / Close the last open HTML tag CTRL+X SPACE Create open/close HTML tags from the typed word CTRL+X CR The same as CTRL+X SPACE but puts a newspace in between CTRL+X ! Insert HTML doctype CTRL+X @ Insert CSS stylesheet CTRL+X # Insert meta content-type meta tag CTRL+X $ Load JavaScript document For the following mappings, suppose that you have typed "foo". Mapping Result --------- ----------- CTRL+X = foo<%=|%> CTRL+X + <%= foo|%> CTRL+X - foo<%|%> CTRL+X _ <% foo|%> CTRL+X ' foo<%#|%> CTRL+X " <%# foo|%>

## How to install ragtag.vim?

To get the latest version:

- 1. Download ragtag.zip.
- 2. Extract ragtag.zip to
`~/.vim`

(on Unix/Linux) or`~\vimfiles`

(on Windows). - 3. Run
`:helptags ~/.vim/doc`

(on Unix/Linux) or`:helptags ~\vimfiles\doc`

(on Windows) to rebuild the tags file (so that you can read help`:help ragtag`

.) - 4. Restart Vim or source ragtag.vim by typing
`:so ~/.vim/plugin/ragtag.vim`

(on Unix/Linux) or`:so ~\vimfiles\plugin\ragtag.vim`

## Have Fun!

Have fun closing those HTML tags and until next time!

I was reading Knuth's "Selected Papers on Computer Science" and in chapter 13 "The IBM 650: An Appreciation from the Field" he had included a photo of a young himself from 1958 at his first computer.

Young Donald Knuth, age 20, at his first IBM 650 computer in 1958.

Don Knuth's first computer, as the chapter's title suggests, was the IBM 650. At that time Knuth had a part-time job helping the statisticians at Case Institute of Technology to draw graphs and do keypunching. Soon a strange new machine was installed across the hall, that the student newspaper called a "giant brain". It was actually an IBM 650.

One afternoon someone at the institute explained some of the machine's internal code to a bunch of freshmen, including Knuth. It all sounded mysterious to him, but it seemed to make a bit of sense, so he got ahold of some manuals. His first chance to try the machine came a few weeks later, when one of the upperclassmen at the fraternity needed to know the five roots of a particular fifth degree equation. Knuth decided to compute the roots using the 650. This was his first program on the 650.

Later Knuth realized how lucky he was to have had such a good first encounter with computers. The polynomial problem was well matched to his mathematical knowledge and interests, and he had a chance for hands-on experience, pushing buttons on the machine and seeing it punch the cards containing the answers.

Knuth's first large program was a tic-tac-toe that learned to play by remembering the relative desirability or undesirability of each position that it had ever encountered. The hardest part, as Knuth writes, was figuring out how to keep one digit of memory for each possible configuration of the board. The machine had just 2000 words of memory, each 10 digits long, plus a sign bit.

Next Knuth proceeded to writing a program that would find prime factors. The idea was that a person could set up any 10-digit number in the console switched and start his program, which would punch the corresponding prime factors on a card and stop. Knuth spent several weeks on this problem, rewriting his program several times. The final program took 11 minutes to determine that the number 9999999967 was prime.

The next major Knuth's program was the improvement of SOAP (Symbolic Optimal Assembly Program) and SOAP II assembly languages. He wrote SOAP III and learned about "creeping featurism," where each of his friends would suggest different things they wanted in an assembler. The program used all 2000 words of memory. Knuth doesn't think he could have gotten by with only 1999 words, because he had spent considerable time finding every last bit of space by using terrible tricks, such as using a single instruction on a specific address that would cause 4 side effects.

Along the way Knuth wrote a lot fun programs. One of the competitions between the students was to do as much as possible with programs that would fit on a single punch card - which had room for only eight instructions. One of the unsolved problems was to take the 10-digit number on the console and to reverse its digits from left to right, then display the answer and stop; nobody could figure out how to do this on a signle card. But one day Knuth proudly marched up to the machine and made a demonstration: he read in a card, then dialled the number 0123456789 on the console, and started the machine. Sure enough, it stopped, displaying the number 9876543210. Everybody applauded. He didn't explain until later that his card would display the number 9876543210 regardless of what number appeared on the console switches. :)

But there is more to the story. One day the IBM 650 machine got an extra set of console switches, that were called register 8004 (top row of switches in the picture). It turned out that nine instructions on an extended 650 were sufficient to reverse the digits of a number, and the ninth instruction could be put into the switches. Therefore he was able to solve the problem without cheating.

Knuth was very close with IBM 650. One night he missed a date with his wife-to-be, because he was so engrossed in debugging that he had forgotten all about the time.

The 650 provided Knuth with solid instruction in the art of programming. It was directly related to the topics of the first two technical articles he ever submitted for publication. Therefore it's not surprising at all that he decided to dedicate The Art of Computer Programming books to the IBM 650 computer. "This series of books is affectionately dedicated to the Type 650 computer once installed at Case Institute of Technology, in remembrance of many pleasant evenings."

**The End.**

If you liked this story, you may want to get Knuth's book "Selected Papers on Computer Science". The collection focuses on Knuth's publications that are addressed primarily to a general audience than to specialists.

**13**Comments February 24, 2010

# MIT Linear Algebra, Lecture 6: Column Space and Null Space

This is the sixth post in an article series about MIT's course "Linear Algebra". In this post I will review lecture six on **column spaces** and **null spaces** of matrices. The lecture first reviews vector spaces and subspaces and then looks at the result of intersect and union of vector subspaces, and finds out when Ax=b and Ax=0 can be solved.

Here is a list of the previous posts in this article series:

- Lecture 1: Geometry of Linear Equations
- Lecture 2: Elimination with Matrices
- Lecture 3: Matrix Multiplication and Inverse Matrices
- Lecture 4: A=LU Factorization
- Lecture 5: Vector Spaces and Subspaces

## Lecture 6: Column Space and Null Space

Lecture six starts with a reminder of what the vector space requirements are. If vectors **v** and **w** are in the space, then the result of adding them and multiplying them by a number stays in the space. In other words, all linear combinations of **v** and **w** stay in the space.

For example, the 3-dimensional space **R**^{3} is a vector space. You can take any two vectors in it, add them, and multiply them by a number and they will still be in the same **R**^{3} space.

Next, the lecture reminds subspaces. A subspace of some space is a set of vectors (including the **0** vector) that satisfies the same two requirements. If vectors **v** and **w** are in the subspace, then all linear combinations of **v** and **w** are in the subspace.

For example, some subspaces of **R**^{3} are:

- Any plane P through the origin (0, 0, 0).
- Any line L through the origin (0, 0, 0).

See the previous, lecture 5, on more examples of spaces on subspaces.

Now suppose we have two subspaces of **R**^{3} - plane P and line L. Is the union P∪L a subspace? **No.** Because if we take some vector in P and some vector in L and add them together, we go outside of P and L and that does not satisfy the requirements of a subspace.

What about intersection P∩L? Is P∩L a subspace? **Yes.** Because it's either the zero vector or L.

In general, given two subspaces S and T, union S∪T is a not a subspace and intersection S∩T is a subspace.

The lecture now turns to **column spaces of matrices**. The notation for a column space of a matrix A is C(A).

For example, given this matrix,

The column space C(A) is all the linear combination of the first (1, 2, 3, 4), the second (1, 1, 1, 1) and the third column (2, 3, 4, 5). That is, C(A) = { a·(1, 2, 3, 4) + b·(1, 1, 1, 1) + c·(2, 3, 4, 5) }. In general, **the column space C(A) contains all the linear combinations of columns of A**.

A thing to note here is that C(A) is a subspace of **R**^{4} because the vectors contain 4 components.

Now the key question, does C(A) fill the whole **R**^{4}? **No.** Because there are only three columns (to fill the whole **R**^{4} we would need exactly 4 columns) and also because the third column (2, 3, 4, 5) is a sum of first column (1, 2, 3, 4) and second column (1, 1, 1, 1).

From this question follows another question, the most important question in the lecture - Does Ax=b have a solution for every right-hand side vector b? **No.** Because the columns are not linearly independent (the third can be expressed as first+second)! Therefore the column space C(A) is actually a two-dimensional subspace of **R**^{4}.

Another important question arises - For which right-hand sides b can this system be solved? The answer is: **Ax=b can be solved if and only if b is in the column space C(A)**! It's because Ax is a combination of columns of A. If b is not in this combination, then there is simply no way we can express it as a combination.

That's why we are interested in column spaces of matrices. They show when can systems of equation Ax=b be solved.

Now the lecture turns to **null spaces of matrices**. The notation for a null space of a matrix A is N(A).

Let's keep the same matrix A:

The null space N(A) contains something completely different than C(N). **N(A) contains all solutions x's that solve Ax=0**. In this example, N(A) is a subspace of **R**^{3}.

Let's find the null space of A. We need to find all x's that solve Ax=0. The first one, obviously, is x = (0, 0, 0). Another one is x = (1, 1, -1). In general all x's (c, c, -c) solve Ax=0. The vector (c, c, -c) can be rewritten as c·(1, 1, -1).

Note that the null space c·(1, 1, -1) is a line in **R**^{3}.

The lecture ends with a proof that solutions x to Ax=0 always give a subspace. The first thing to show in the proof is that if x is a solution and x' is a solution, then their sum x + x' is a solution:

We need to show that if Ax=0 and Ax' = 0 then A(x + x') = 0. This is very simple. Matrix multiplication allows to separate A(x + x') into Ax + Ax' = 0. But Ax=0 and Ax'=0. Therefore 0 + 0 = 0.

The second thing to show is that if x is a solution, then c·x is a solution:

We need to show that if Ax=0 then A(c·x)=0. This is again very simple. Matrix multiplication allows to bring c from A(c·x) outside c·A(x) = c·0 = 0.

That's it. We have proven that solutions x to Ax=0 always form a subspace.

Here is the video of the sixth lecture:

Direct link: http://www.youtube.com/watch?v=8o5Cmfpeo6g

Topics covered in lecture six:

- [01:00] Vector space requirements.
- [02:10] Example of spaces R
^{3}. - [02:40] Subspaces of spaces.
- [03:00] A plane P is a subspace of R
^{3}. - [03:50] A line L is a subspace of R
^{3}. - [04:40] Union of P and L.
- [07:30] Intersection of P and L.
- [09:00] Intersection of two subspaces S and T.
- [11:50] The column space C(A) of a matrix A.
- [16:20] Does Ax=b have a solution for every b?
- [19:45] Which b's allow Ax=b to be solved?
- [23:50] Can solve Ax=b exactly when b is in C(A).
- [28:50] The null space N(A) of a matrix A.
- [37:00] Why is the null space a vector space?
- [37:30] A proof that the null space is always a vector space.
- [41:50] Do the solutions to Ax=b form a subspace?

Here are my notes of lecture six:

Have fun with this lecture! The next post is going to be about general theory of solving equations Ax=0, pivot variables and special solutions.

PS. This course is taught from Introduction to Linear Algebra textbook. Get it here: