{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# MATH 382 - Fall 2018\n", "## Scientific Computing\n", "Yor Name Here\n", "\n", "${\\bf Directions:}$ Write the solutions of the five problems below (code and text as needed) in this notebook and submit it in canvas.\n", "
\n", "# Lab Assignment 1: Linear Algebra\n", "
" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "## Problem \\#1\n", "\n", "Create the following matrices and print them along with their data type\n", "\n", "(a) A $3 \\times 3$ diagonal matrix $A$ of type double with diagonal entries $(1, -1, 2)$" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A = [[ 1. 0. 0.]\n", " [ 0. -1. 0.]\n", " [ 0. 0. 2.]] \n", "\n", "float64 \n", "\n" ] } ], "source": [ "# Enter your code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "(b) A $4 \\times 3$ diagonal matrix $B$ of type int with diagonal entries $(1, -1, 2)$. $Hint:$ Use np.vstack" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "B = [[ 1 0 0]\n", " [ 0 -1 0]\n", " [ 0 0 2]\n", " [ 0 0 0]] \n", "\n", "int64 \n", "\n" ] } ], "source": [ "# Enter your code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "(c) A $3 \\times 4$ matrix $C$ of type double with diagonal entries $(1, -1, 2)$. $Hint:$ Use np.hstack" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C = [[ 1. 0. 0. 0.]\n", " [ 0. -1. 0. 0.]\n", " [ 0. 0. 2. 0.]] \n", "\n", "float64 \n", "\n" ] } ], "source": [ "# Enter your code here" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "
\n", "## Problem \\#2\n", "(a) Create the $4 \\times 4$ matrix of type double\n", "$$\n", "A = \\left(\\begin{array}{cccc} 2 & -1 & 0 & 0 \\\\ -1 & 2 & -1 & 0\\\\ 0 & -1 & 2 & -1 \\\\ 0 & 0 & -1 & 2 \\end{array} \\right)\n", "$$\n", "And print it along with its data type" ] }, { "cell_type": "code", "execution_count": 61, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A = [[ 2. -1. 0. 0.]\n", " [-1. 2. -1. 0.]\n", " [ 0. -1. 2. -1.]\n", " [ 0. 0. -1. 2.]] \n", "\n", "float64 \n", "\n" ] } ], "source": [ "# Enter your code here" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "
\n", "\n", "(b) Is A invertable? Explain your answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "(c) Find the eigen decomposition of $A$, $A = V \\Lambda V^{-1}$, and print the matrices $V$ and $\\Lambda$" ] }, { "cell_type": "code", "execution_count": 62, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "V = [[-0.37174803 -0.60150096 -0.37174803 -0.60150096]\n", " [ 0.60150096 0.37174803 -0.60150096 -0.37174803]\n", " [-0.60150096 0.37174803 -0.60150096 0.37174803]\n", " [ 0.37174803 -0.60150096 -0.37174803 0.60150096]] \n", "\n", "Lambda = [[ 3.61803399 0. 0. 0. ]\n", " [ 0. 2.61803399 0. 0. ]\n", " [ 0. 0. 0.38196601 0. ]\n", " [ 0. 0. 0. 1.38196601]] \n", "\n" ] } ], "source": [ "# Enter your code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "(d) Is the matrix $V$ orthogonal? Explain your answer" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "
\n", "## Problem \\#3\n", "\n", "Consider the syste $A{\\bf x} = {\\bf b}$ with\n", "$$\n", "A = \\left( \\begin{array}{ccc} 1 & -1 & 2 \\\\ 2 & 0 & -1 \\\\ 1 & 0 & 2 \\\\ -2 & 3 & -2 \\end{array}\\right) \\ \\ \\ \\ \\ \\ \\ \\ \\ \\text{and} \\ \\ \\ \\ \\ \\ \\ \\ \\\n", "{\\bf b} = \\left( \\begin{array}{ccc} 1 \\\\ 0 \\\\ 2 \\\\ 1 \\end{array}\\right)\n", "$$\n", "\n", "(a) Does the system have any solutions? Explain\n", "
\n", "\n", "(b) Find the Singular Value Decomposition of $A$, $A = U D V^\\top$, and print $U$, $D$, and $V$\n", "
\n", "\n", "(c) Find and print $A$'s Moore-Penrose pseudo inverse $A^{+}$\n", "
\n", "\n", "(d) Find and print the approximate solution to the given system, $\\widehat{\\bf x}$, that minimizes the error $\\| A{\\bf \\widehat{x}} - {\\bf b} \\|_2$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "## Problem \\#4\n", "\n", "Consider the system in Problem \\#3 with ${\\bf b} = \\left(1, 0, 2, \\alpha \\right)^\\top$\n", "\n", "(a) For what value(s) of $\\alpha$ does the system have a unique solution?\n", "
\n", "\n", "(b) Find it." ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "
\n", "## Problem \\#5\n", "\n", "For the matrix $A$ in Problem \\#3\n", "\n", "(a) Find the eigen value decomposition of the matrix $A^\\top A$.\n", "
\n", "\n", "(b) How are the eigen values and eigen vectors of $A^\\top A$ related to the singular values and singular vectors of $A$?\n", "
\n", "\n", "(c) Find the eigen value decomposition of the matrix $AA^\\top$. \n", "
\n", "\n", "(d) How are the eigen values and eigen vectors of $AA^\\top$ related to the singular values and singular vectors of $A$?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 1 }