{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Here is how you can define the matrix $$ M = \\begin{pmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \\\\ 7 & 8 &9 \\\\ 10 & 11 & 12 \\end{pmatrix}$$\n", "You list all the rows of the matrix:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "M = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) #note the brackets and parentheses!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is how you can define the vector:\n", "$$ v = \\begin{pmatrix} 2 \\\\ 1 \\\\8 \\end{pmatrix} = (2, 1, 8)$$" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "v = vector((2,1,8))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can multiply the matrix times the vector since the dimensions work out." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(28, 61, 94, 127)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M*v" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can multiply matrices similarly. Let $$N = \\begin{pmatrix}2 & 7 \\\\ 1 & -3 \\\\ 8 & 0 \\end{pmatrix}$$\n", "We compute the matrix $MN$." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "N = Matrix([[2,7],[1, -3], [8, 0]])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[ 28 1]\n", "[ 61 13]\n", "[ 94 25]\n", "[127 37]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M*N" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using a Juypter Notebook (as on sage.colby.edu) we can make it display it in a prettier fashion." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "%display latex # you can include this command just once at the top of your document" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\left(\\begin{array}{rrr}\n", "1 & 2 & 3 \\\\\n", "4 & 5 & 6 \\\\\n", "7 & 8 & 9 \\\\\n", "10 & 11 & 12\n", "\\end{array}\\right)\\)" ], "text/latex": [ "$\\displaystyle \\left(\\begin{array}{rrr}\n", "1 & 2 & 3 \\\\\n", "4 & 5 & 6 \\\\\n", "7 & 8 & 9 \\\\\n", "10 & 11 & 12\n", "\\end{array}\\right)$" ], "text/plain": [ "[ 1 2 3]\n", "[ 4 5 6]\n", "[ 7 8 9]\n", "[10 11 12]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\left(\\begin{array}{rr}\n", "2 & 7 \\\\\n", "1 & -3 \\\\\n", "8 & 0\n", "\\end{array}\\right)\\)" ], "text/latex": [ "$\\displaystyle \\left(\\begin{array}{rr}\n", "2 & 7 \\\\\n", "1 & -3 \\\\\n", "8 & 0\n", "\\end{array}\\right)$" ], "text/plain": [ "[ 2 7]\n", "[ 1 -3]\n", "[ 8 0]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "N" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\\(\\displaystyle \\left(\\begin{array}{rr}\n", "28 & 1 \\\\\n", "61 & 13 \\\\\n", "94 & 25 \\\\\n", "127 & 37\n", "\\end{array}\\right)\\)" ], "text/latex": [ "$\\displaystyle \\left(\\begin{array}{rr}\n", "28 & 1 \\\\\n", "61 & 13 \\\\\n", "94 & 25 \\\\\n", "127 & 37\n", "\\end{array}\\right)$" ], "text/plain": [ "[ 28 1]\n", "[ 61 13]\n", "[ 94 25]\n", "[127 37]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M*N" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.6", "language": "sage", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }