{ "cells": [ { "cell_type": "markdown", "metadata": { "toc-hr-collapsed": true }, "source": [ "# SEFI Workshop \"Teaching and Learning with Jupyter Notebooks\" \n", "15 Sept. 2021 \n", "C. Hardebolle \n", "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n", "\n", "
shift + enter
. Figure 1: The suspended jeans situation
\n", "\n", "\n", "The activities below allow you to find out the answer to this question by exploring how the counterweight affects the position of the jeans suspended on the cable. " ] }, { "cell_type": "markdown", "metadata": { "toc-hr-collapsed": false }, "source": [ "def tension_norm(g, m, alpha):\n",
" tension = (1/2 * m * g) / np.sin(alpha)\n",
" return tension\n",
"
\n",
"\n",
"T = tension_norm(g, m, 0)
\n",
" \n",
"When you execute this code, two things happen:\n",
"* You get a warning message which says `RuntimeWarning: divide by zero encountered in double_scalars`\n",
"* The function nonetheless returns a value which is `inf`\n",
"\n",
"When the angle $\\alpha$ = 0 then $sin(\\alpha)$ = 0 and therefore we divide `(.5 * jeans_mass * gravity)` by 0 so on one hand, mathematically speaking, we know that the result should be $+\\infty$. On the other hand, we also know that usually division by 0 is not well supported by computers.\n",
"\n",
"Actually, division by 0 is not supported in standard Python. \n",
"You can create a code cell (click on the `+` icon in the toolbar above) and try to execute the following computation to see what happens: ``(0.5 * 3 * 9.81)/0``\n",
" \n",
"Now, because in the calculation we use the function `np.sin()` from the Numpy library, our data is automatically converted to Numpy types, which support division by zero and returns the \"real\" result which is $+\\infty$. \n",
"By convention, Numpy also generates a warning message but this can be deactivated when not necessary. \n",
"If you are curious, you can take a look at [the errors generated by Numpy for floating-point calculations](https://docs.scipy.org/doc/numpy/reference/generated/numpy.seterr.html#numpy.seterr).\n",
"\n",
"def tension_norm_degrees(g, m, alpha):\n",
" apha_rad = degrees_to_radians(alpha)\n",
" tension = tension_norm(g, m, apha_rad)\n",
" return tension\n",
"
\n",
"\n",
"Of course the three lines in this function can be combined into just one: \n",
"\n",
"def tension_norm_degrees(g, m, alpha):\n",
" return tension_norm(g, m, degrees_to_radians(alpha))\n",
"
\n",
" \n",
"