Skip to content

Instantly share code, notes, and snippets.

@tobydriscoll
Created August 30, 2016 21:20
Show Gist options
  • Save tobydriscoll/2c2a21256da6efab7433bf42371a43f2 to your computer and use it in GitHub Desktop.
Save tobydriscoll/2c2a21256da6efab7433bf42371a43f2 to your computer and use it in GitHub Desktop.
Lecture01-matlab
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Lecture 1. Matrix-Vector Multiplication"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Matrix times vector"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A matrix right-multiplied by a column vector---that is, $\\mathbf{A}\\mathbf{x}$---is a linear combination of the columns of $\\mathbf{A}$, with coefficients of the combination given by the entries of $\\mathbf{x}$. For example,"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A =\n",
"\n",
" 8 1 6\n",
" 3 5 7\n",
" 4 9 2\n",
"\n",
"\n",
"x =\n",
"\n",
" -1\n",
" 2\n",
" 1\n"
]
}
],
"source": [
"A = magic(3), x = [-1;2;1]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans =\n",
"\n",
" 0\n",
" 14\n",
" 16\n"
]
}
],
"source": [
"A*x"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans =\n",
"\n",
" 0\n",
" 14\n",
" 16\n"
]
}
],
"source": [
"x(1)*A(:,1) + x(2)*A(:,2) + x(3)*A(:,3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this context it's clear why the number of entries in $\\mathbf{x}$ has to be the same as the number of columns in $\\mathbf{A}$."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you left-multiply a matrix by a vector, it should be a row vector. I'll be using column vectors exclusively, so we have to transpose (or conjugate transpose) to get the row shape. Transposition of the product also makes the interpretation clear:\n",
"\n",
"$$\n",
"\\mathbf{y}^* \\mathbf{A} = \\bigl( \\mathbf{A}^* \\mathbf{y}\\bigr)^*,\n",
"$$\n",
"\n",
"which is the (conjugate) transpose of the columns of $\\mathbf{A}^*$, i.e., the rows of $\\mathbf{A}$."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Linear algebra, including abstract linear algebra, is built in large part on linear combinations. The vectors that one combines need not be ordinary vectors in $\\mathbb{C}^n$. For instance, a polynomial is a linear combination of monomials. We can encompasss this fact too by generalizing the notion of a \"matrix\":\n",
"\n",
"$$\n",
"c_0 + c_1 t + \\cdots c_n t^n = \\begin{bmatrix} 1 & t & \\cdots & t^n \\end{bmatrix} \\begin{bmatrix}c_0 \\\\ c_1 \\\\ \\vdots \\\\ c_n \\end{bmatrix}.\n",
"$$\n",
"\n",
"The \"matrix\" here is sometimes called a *quasimatrix*. From here it's a small step to imagine choosing many values of $t$ in an interval and converting the quasimatrix into a proper matrix. This is easy to carry out in MATLAB."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGkCAIAAACgjIjwAAAACXBIWXMAABcSAAAXEgFnn9JSAAAA\nB3RJTUUH4AgeDg03XassBwAAACR0RVh0U29mdHdhcmUATUFUTEFCLCBUaGUgTWF0aFdvcmtzLCBJ\nbmMuPFjdGAAAACJ0RVh0Q3JlYXRpb24gVGltZQAzMC1BdWctMjAxNiAxMDoxMzo1NcffZ54AACAA\nSURBVHic7d1/cFXlve/xbxLAQGQbBCETEwwXmCg4mIwpUE4P8kMH7Iyc8R60w9S2OjAW255CR5Hr\nyNAjzEUtlROutocZW9vpjNXDD6XMSMPcUxOqKBQYQAYOkBRySLovQigxIQmBJNw/Hl0s1lp77d97\nPWut9+uPzsrOys6iZ598+nyf7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AgAQC08P8Ba5QWcI98OoIAAAAASUVORK5CYII=\n",
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"V = zeros(51,4); % not strictly necessary\n",
"t = linspace(0,1,51)'; \n",
"for j = 0:3, V(:,j+1) = t.^j; end\n",
"plot(t,V)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Matrix times matrix"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It's often useful to think of a matrix-matrix product as a collection of matrix-vector products. For example,"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"C =\n",
"\n",
" 16 18 21\n",
" 5 16 26\n",
" 9 16 22\n",
" 4 18 33\n"
]
}
],
"source": [
"A = magic(4); B = triu(ones(4,3)); \n",
"C = A*B"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans =\n",
"\n",
" 16 18 21\n",
" 5 16 26\n",
" 9 16 22\n",
" 4 18 33\n"
]
}
],
"source": [
"[ A*B(:,1), A*B(:,2), A*B(:,3) ]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Hence the number of rows in $\\mathbf{B}$ has to be the same as the number of columns in $\\mathbf{A}$. In the special case where that number is 1, then $\\mathbf{A}$ is a column vector and $\\mathbf{B}$ is a row vector, and the result is called a **vector outer product**. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans =\n",
"\n",
" 4 1\n",
"\n",
"\n",
"ans =\n",
"\n",
" 1 3\n"
]
}
],
"source": [
"u = [ 1; 2; 3; 4 ]; v = [ 1i -1i 1 ];\n",
"size(u), size(v)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans =\n",
"\n",
" 0.0000 + 1.0000i 0.0000 - 1.0000i 1.0000 + 0.0000i\n",
" 0.0000 + 2.0000i 0.0000 - 2.0000i 2.0000 + 0.0000i\n",
" 0.0000 + 3.0000i 0.0000 - 3.0000i 3.0000 + 0.0000i\n",
" 0.0000 + 4.0000i 0.0000 - 4.0000i 4.0000 + 0.0000i\n"
]
}
],
"source": [
"u*v"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rank and inverse"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The rank and inverse of a matrix are of critical importance in linear algebra. It's important to be aware, however, that they are not robust to perturbations. For example, it should be clear that this matrix is singular and of rank 1."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A =\r\n",
" 0 1\r\n",
" 0 0\r\n",
"ans =\r\n",
" 1\n"
]
}
],
"source": [
"A = [ 0 1; 0 0 ]\n",
"rank(A)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"However, any perturbation of the second row, no matter how small, mathematically changes the rank to 2 and thus makes the matrix invertible."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"B =\r\n",
" 0 1.0000e+00\r\n",
" 1.0000e-12 0\r\n",
"ans =\r\n",
" 2\n"
]
}
],
"source": [
"format short e\n",
"B = A + [0 0; 1e-12 0 ]\n",
"rank(B)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In numerical computation, representation of and arithmetic with real numbers cannot be exact. Therefore, the notions of rank and invertibility will have to be carefully reconsidered. In fact, it's questionable as to whether you should ever compute a matrix rank in finite precision. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Change of basis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In linear algebra one learns that a matrix is the expression of a linear transformation relative to a particular basis. Unless stated otherwise, when we write out the numerical values of a matrix, we have chosen the standard basis, whose elements are the columns of an identity matrix. \n",
"\n",
"Say we have a basis whose elements, when expressed in the standard basis, are the columns of a square matrix $\\mathbf{A}$. Let a vector $\\mathbf{v}$ be given as coordinates $x_1,x_2,\\ldots$ in that basis. Then we can convert the coordinates of $\\mathbf{v}$ to standard by matrix--vector multiplication:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"v_standard =\r\n",
" 5\r\n",
" 16\r\n",
" 9\n"
]
}
],
"source": [
"A = magic(3); x = [ -1; 1; 2 ];\n",
"v_standard = A*x"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consequently, we can convert a vector from standard coordinates to the \"$\\mathbf{A}$-basis\" through multiplication by $\\mathbf{A}^{-1}$. "
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"v_Abasis =\r\n",
" -1.0000e+00\r\n",
" 1.0000e+00\r\n",
" 2.0000e+00\n"
]
}
],
"source": [
"v_Abasis = A^(-1) * v_standard"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that while `A^(-1)*` works in MATLAB, *it is not recommended*, for reasons we will go into later. A mathematically equivalent but computationally preferable syntax is to use `A\\` instead."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"v_Abasis =\r\n",
" -1\r\n",
" 1\r\n",
" 2\n"
]
}
],
"source": [
"v_Abasis = A \\ v_standard"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Matlab",
"language": "matlab",
"name": "matlab"
},
"language_info": {
"codemirror_mode": "octave",
"file_extension": ".m",
"help_links": [
{
"text": "MetaKernel Magics",
"url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
}
],
"mimetype": "text/x-octave",
"name": "matlab",
"version": "0.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment