{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Homework 9"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 1\n",
    "\n",
    "Study carefully all of the material in the lecture notes on loops (the key version) and on the Newton examples. I recommend that you type what you see. It is important to read, and understand, and internalize. Ask yourself questions: why is it like this? what if I try that? Try coming up with your own test problems.\n",
    "\n",
    "In a markdown cell below, just state if you did this. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 2\n",
    "Use for loops that will output the multiplication table for numbers from 1 to 10 inclusive. The output should look like a table with rows and columns, but they don't have to be perfectly aligned (though that is easy with a formatted string like ```print(f\"{x:4d})\"``` where ```x``` is the variable or expression holding the number you are printing). Note, print can be called with the optional argument end, like so:\n",
    "```\n",
    "print(f\"{x:4d})\", end=\"\")\n",
    "```\n",
    "This will print x without making a new line.\n",
    "\n",
    "You don't need column and row headings, just the product. For 3x2 = 6, you just need the \"6\" in the correct position of the table."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 3\n",
    "\n",
    "As we go up in the atmosphere, the pressure and temperature decrease. We can calculate how they change by using a force balance to obtain\n",
    "\n",
    "$$\\frac{dP}{dz} = -\\rho g,$$\n",
    "\n",
    "where $P$ is pressure, $z$ is height, $\\rho$ is air density, and $g$ is gravitational acceleration. We can use the ideal gas law:\n",
    "\n",
    "$$\\rho = \\frac{M P}{R T},$$\n",
    "\n",
    "where $M$ is the mean molecular weight of air, $T$ is temperature (K), and $R$ is the gas constant. If we insert this equation for $\\rho$ in the first equation, separate variables, and integrate, we get\n",
    "\n",
    "<font color=\"blue\">\n",
    "\n",
    "$$P_{iso} = P_{sea}\\exp(-Mgz/(RT)),$$\n",
    "\n",
    "</font>\n",
    "\n",
    "where $P_{sea}$ = 1 atm.\n",
    "This equation assumes constant temperature (isothermal). \n",
    "\n",
    "Take M=29 kg/kmol, g=9.81 m/$s^2$, T=300 K.\n",
    "\n",
    "Write a function that will take z as a function argument and return the pressure (blue equation). Evaluate this function in a loop and print the value of z and P at uniform values of z between z=0 and z= 30,000 ft (Mt. Everest). Output around 30 values. Your output on each line should look something like\n",
    "\n",
    "z (m), P (atm) = 100, 0.9\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Problem 4\n",
    "\n",
    "Write a function called ```EE``` to solve the following rate equation using the Explicit Euler method.\n",
    "\n",
    "$$\\frac{dT}{dt} = \\frac{hA}{mc_p}(T_f-T),$$\n",
    "$$T_0 = 500\\,\\,K.$$\n",
    "\n",
    "This equation represents the convective heating of an object of mass $m$, area $A$, and heat capacity $c_p$.\n",
    "\n",
    "- Recall, for explicit Euler, for the rate equation $dy/dt = f(y,t)$, we have\n",
    "\n",
    "$$y_{n+1} = y_n + \\Delta t f(y_n,t_n).$$\n",
    "\n",
    "- Use the following\n",
    "    - $h$   = 1 W/$m^2$*K\n",
    "    - $A$   = 1 $m^2$\n",
    "    - $m$   = 1 kg\n",
    "    - $c_p$ = 1 J/kg*K\n",
    "    - $T_f$ = 1000 K\n",
    "    \n",
    "- Use a stepsize $\\Delta t=0.2$, and take 30 steps. \n",
    "- Output the time, and temperature at each step.\n",
    "- (We'll plot the resulting $T(t)$ when we learn to plot in Python.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.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": 1
}
