{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Assignment 4: Linear Algebra Review" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**1**. (20 points)\n", "\n", "Consider the linear transformation $f(x)$ on $\\mathbb{R}^3$ that takes the standard basis $\\left\\{e_1,e_2,e_3\\right\\}$ to $\\left\\{v_1,v_2,v_3\\right\\}$ where\n", "\n", "$$v_1=\\left(\\begin{matrix}10\\\\-10\\\\16\\end{matrix}\\right), v_2=\\left(\\begin{matrix}2\\\\-5\\\\20\\end{matrix}\\right) \\textrm {and } v_3=\\left(\\begin{matrix}1\\\\-4\\\\13\\end{matrix}\\right)$$\n", "\n", "1. Write a matrix $A$ that represents the same linear transformation. (4 points)\n", "\n", "2. Compute the rank of $A$ using two different methods (do not use `matrix_rank`!). (4 points)\n", "\n", "3. Find the eigenvalues and eigenvectors of $A$. (4 points)\n", "\n", "4. What is the matrix representation of $f$ with respect to the eigenbasis? (8 points)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**2**. (20 points)\n", "\n", "You are given the following x-y coordinates (first column is x, second is y)\n", "\n", "```\n", "array([[ 0. , 4.12306991],\n", " [ 3. , -15.47355729],\n", " [ 4. , -11.68725507],\n", " [ 3. , -20.33756693],\n", " [ 5. , -6.06401989],\n", " [ 6. , 32.79353057],\n", " [ 8. , 82.48658405],\n", " [ 9. , 84.02971858],\n", " [ 4. , -1.30587276],\n", " [ 8. , 68.59409878]])\n", "```\n", "\n", "- Find the coefficients $(a, b, c)$ of the least-squares fit of a quadratic function $y = a + bx + cx^2$ to the data. \n", "- Plot the data and fitted curve using `matplotlib`.\n", "\n", "Note: Use `numpy.linalg.leastsq` function to solve this." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**3**. (20 points)\n", "\n", "Consider the following system of equations:\n", "\n", "$$\\begin{align*}\n", "2x_1& - x_2& +x_x &=& 6\\\\\n", "-x_1& +2x_2& - x_3 &=& 2\\\\\n", " x_1 & -x_2& + x_3 &=& 1\n", "\\end{align*}$$\n", "\n", "1. Consider the system in matrix form $Ax=b$ and define $A$, $b$ in numpy.\n", "2. Show that $A$ is positive-definite\n", "3. Use the appropriate matrix decomposition function in numpy and back-substitution to solve the system. Remember to use the structure of the problem to determine the appropriate decomposition.\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**4**. (40 points)\n", "\n", "You are given the following set of data to fit a quadratic polynomial to\n", "\n", "```python\n", "x = np.arange(10)\n", "y = np.array([ 1.58873597, 7.55101533, 10.71372171, 7.90123225,\n", " -2.05877605, -12.40257359, -28.64568712, -46.39822281,\n", " -68.15488905, -97.16032044])\n", "```\n", "\n", "- Find the least squares solution by using the normal equations $A^T A \\hat{x} = A^T y$. (5 points)\n", "\n", "- Write your own **gradient descent** optimization function to find the least squares solution for the coefficients $\\beta$ of a quadratic polynomial. Do **not** use a gradient descent algorithm from a package such as `scipy-optimize` or `scikit-learn`. You can use a simple for loop - start with the parameters `beta = np.zeros(3)` with a learning rate $\\alpha = 0.0001$ and run for 100000 iterations. (15 points)\n", "\n", "- Plot the data together with the fitted polynomial. (10 points)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "\n" ] } ], "metadata": { "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.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }