{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Homework 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "from scipy.integrate import quad\n",
    "from scipy.interpolate import interp1d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Problem 1\n",
    "Given the data `x` and `y` below. Find the linear interpolate `yi` corresponding to `xi=0.54`. Also find the cubic spline (read the notes) value of y at the same point. The `xg` and `yg` values are computed from $y=f(x)=\\exp(4x)$. Find the relative error between your interpolants and the exact value. The relative error is given by $\\epsilon = |(y-y_{exact})/y_{exact}|$. Are you happy with the result?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.array([0,0.2,0.4,0.8,1.0])\n",
    "y = np.exp(4.0*x)\n",
    "\n",
    "xi     = 0.54\n",
    "yexact = np.exp(4.0*xi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Problem 2\n",
    "\n",
    "- Data from a turbulent jet simulation is given in file [hw_20_data.txt](http://ignite.byu.edu/cbe263/homework/hw_20_data.txt).\n",
    "\n",
    "- Download this data into a file called hw_20_data.txt and load it into a matrix.\n",
    "- Plot the column labeled `pos` versus the column labeled `uvel` (that is, column 0 versus column 4). \n",
    "    - Label the axes as \"position (m)\" and \"velocity (m/s)\".\n",
    "- The x-data values are not uniform because this simulation was performed on an adaptive grid. However, for convenient data processing, we want the data on a uniform grid.\n",
    "- Find the minimum grid point spacing (the minimum spacing between x points). Then make a uniform grid of x points with that spacing.\n",
    "- Then, interpolate the original uvel array to the new uniform grid. Use linear interpolation.\n",
    "- On a new plot, plot the interpolated uvel versus position."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "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.4"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
