{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# EART 70013 \n", " \n", "# Geophysical Inversion \n", " \n", "## Lecture 1 - Homework Solutions " ] }, { "cell_type": "markdown", "metadata": { "toc": true }, "source": [ "

Table of Contents

\n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import scipy.linalg as sl\n", "import scipy.optimize as sop\n", "from pprint import pprint" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Homework" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework - Checking properties of transposes\n", "\n", "Check the four properties of the transpose operator from the lecture for some example matrices.\n", "\n", "Hint: \n", "\n", "```Python\n", "A = np.random.random((m,n))\n", "```\n", "\n", "is a convenient way to generate an arbitrary m by n matrix." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework - Prove that $(AB)^T = B^T A^T$\n", "\n", "As per the section title!\n", "\n", "Hint: Writing in index notation $A = [a_{ij}]_{m\\times n}$ and $B = [b_{ij}]_{n\\times p}$\n", "the product can be defined as: the $(i,j)$-th entry of the product $AB$ is given by\n", "$$\\sum_{k=1}^n a_{ik} b_{kj}$$\n", "with $A$ being an $m\\times p$ matrix." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework - Symmetric matrices\n", "\n", "1. Given an $n\\times n$ symmetric matrix $A$ and an arbitrary $m\\times n$ matrix B, show that the matrix $BAB^T$ is symmetric.\n", "\n", "Verify through an example using NumPy.\n", "\n", "\n", "\n", "2. If $A$ and $B$ are both symmetric square matrices, are $AB+BA$ and $AB-BA$ symmetric or skew-symmetric?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework - Matrix-vector multiplication as a weighted sum of columns\n", "\n", "In the lecture we pointed out \"another useful interpretation\" of matrix vector multiplication.\n", "\n", "Code up this approach and perform the same testing that we did in the lecture for `def mat_vec_product(A, x)`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework - Fitting two data points\n", "\n", "We stated in class that:\n", "\n", "\n", "The polynomial that fits the two data points $\\{(x_0,y_0),(x_1,y_1)\\}$ is clearly the linear function given by\n", "\n", "$$ y = f(x) \\equiv a_0 + a_1\\,x \\;\\;\\;\\;\\; \\text{i.e. the degree one polynomial:} \\;\\;\\;\\;\\; y = P_1(x) \\equiv a_0 + a_1\\,x$$\n", "\n", "where through substitution we arrive at two simultaneous equations (or a $2\\times 2$ matrix system) which can fairly easily be solved by substituting one equation into the other to conclude that\n", "\n", "$$ a_0 = y_0 - \\frac{y_1-y_0}{x_1-x_0}x_0, \\;\\;\\;\\;\\;\\;\\;\\; a_1 = \\frac{y_1-y_0}{x_1-x_0}. $$\n", "\n", "Form the set of two simultaneous equations and solve by hand to derive this solution for the coefficients.\n", "\n", "
\n", "\n", "Confirm that this result is exactly the same as the Lagrange polynomial (we saw in the lecture) that you can just write down without needing to invert any system for coefficients." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework - Squared error calculation (from Numerical Methods)\n", "\n", "As described in the docs ([numpy.polyfit](http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html)), least squares fitting minimises the square of the difference between the data provided and the polynomial,\n", "\n", "$$E = \\sum_{i=0}^{N} (p(x_i) - y_i)^2,$$\n", "\n", "where $p(x_i)$ is the value of the polynomial function that has been fit to the data evaluated at point $x_i$, and $y_i$ is the $i^{th}$ data value.\n", "\n", "Write a Python function that evaluates the squared error, $E$, and use this function to evaluate the error for each of the polynomials calculated below. \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Homework - Degree of approximation (from Numerical Methods)\n", "\n", "Extend the previous question above by fitting and plotting polynomials of increasing degree past cubic. At what *degree* does the resulting polynomial approximation fit the data exactly?\n" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.7.13" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": true, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": true }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 1 }