{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Matrix Multiplication Practice" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " In this notebook you'll be able to practice matrix multiplication with randomly generated problems. Notice the special shapes that come up! You should encounter, as matrix-matrix multiplication, 8 problem types:\n", "\n", "\n", "\n", "Each problem type is equally likely, so you'll be able to practice the special cases more often. Try guessing the problem type every time one pops up. Guess the most specific case of matrix-matrix multiplication. (Yes, you could guess \"matrix-vector multiplication\" when it is also a scalar multiplication.)\n", "\n", "A lot of people get confused between Dot and Outer products, and they are really important." ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Usage" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the three cells below. The routines should be pretty self explanatory, but you can re-run the first code block to get a new random problem as many times as you'd like. The variable p stores the answer to the problem you've generated, so use the p.show_answer() code block to reveal the answer and the p.show_problem_type() code block to reveal the problem type." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import generate_problems as gp\n", "\n", "p = gp.Problem()\n", "p.new_MM()" ], "language": "python", "metadata": {}, "outputs": [ { "latex": [ "$$\\left[\\begin{matrix}4 & -1 & 3 & -1\\\\4 & -4 & 0 & 3\\\\2 & -3 & 3 & -2\\\\-2 & -1 & 1 & -2\\end{matrix}\\right] \\left[\\begin{matrix}-2\\\\-2\\\\-2\\\\-4\\end{matrix}\\right]=?$$" ], "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "p.show_answer()" ], "language": "python", "metadata": {}, "outputs": [ { "latex": [ "$$\\left[\\begin{matrix}4 & -1 & 3 & -1\\\\4 & -4 & 0 & 3\\\\2 & -3 & 3 & -2\\\\-2 & -1 & 1 & -2\\end{matrix}\\right] \\left[\\begin{matrix}-2\\\\-2\\\\-2\\\\-4\\end{matrix}\\right]=\\left[\\begin{matrix}-8\\\\-12\\\\4\\\\12\\end{matrix}\\right]$$" ], "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "p.show_problem_type()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "This is a Matrix-Vector Product problem\n" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }