{ "cells": [ { "cell_type": "markdown", "metadata": { "toc-hr-collapsed": true }, "source": [ "\n", "# Workshop \"Teaching Sciences and Engineering with Jupyter Notebooks\" 2022-2023" ] }, { "cell_type": "markdown", "metadata": { "tags": [], "toc-hr-collapsed": true }, "source": [ "This notebook is a **demonstration example**, to illustrate different possibilities allowed by the technology, as well as best practices to maximize learning for students.\n", "\n", "This notebook is meant to be used as if you were a student. \n", "To get a realistic experience, I advise you to **really try to perform the activities** (there are only 4 exercises, this should take you something like 20 minutes maximum)." ] }, { "cell_type": "markdown", "metadata": { "toc-hr-collapsed": true }, "source": [ "
shift + enter
. It is important to execute the code cells in their order of appearance in the notebook.\n",
"Figure 1: Simplified suspended jeans situation
\n", "\n", "\n", "In addition, we can also suppose that the jeans are positioned exactly mid-way between the poles. \n", "Therefore we are in a situation which is identical to the one seen in the mini-lecture: it's like **the jeans are suspended with two identical cables on both sides**.Figure 2: Angle and forces in the suspended jeans situation
\n", "\n", "def tension_norm(g, m, alpha):\n",
" tension = (1/2 * m * g) / np.sin(alpha)\n",
" return tension\n",
"
\n",
"\n",
"Figure 3: Forces on the counterweight
\n", "\n", "We can write this as an equation: \n", "$\n", "\\begin{align}\n", "\\lvert\\vec{T}\\rvert = \\lvert\\vec{F_{cw}}\\rvert\n", "\\end{align}\n", "$\n", "\n", "Since the weight of the counterweight is $\\lvert\\vec{F_{cw}}\\rvert = m_{cw}.g$, we can therefore write: \n", "$\n", "\\begin{align}\n", "\\lvert\\vec{T}\\rvert = m_{cw}.g\n", "\\end{align}\n", "$\n", "\n", "From there we can find the mass of the counterweight $m_{cw}$: \n", "$\n", "\\begin{align}\n", "m_{cw} = \\frac{\\lvert\\vec{T}\\rvert}{g}\n", "\\end{align}\n", "$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using Python for the computation\n", "\n", "Again we can use python to make this simple computation, using the values `T` and `g` computed earlier." ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "m_cw = T / g
\n",
" \n",
"Of course, if you are at ease with Python you can write this as a function, which could also call the ``tension_norm`` function defined earlier instead of using ``T``, which would be a better programming design...\n",
"\n",
"For an angle of $\\alpha$ = 2$^\\circ$, you should find a mass ``m_cw`` = 42.98056252176573 kg. \n",
"Note: If you changed the value of $\\alpha$ in the previous cell, then you will find a different mass for the counterweight.\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 return 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",
"