{ "cells": [ { "cell_type": "markdown", "metadata": { "toc-hr-collapsed": true }, "source": [ "# Workshop \"Teaching Sciences and Engineering with Jupyter Notebooks\" 2023-2024" ] }, { "cell_type": "markdown", "metadata": { "toc-hr-collapsed": true }, "source": [ "
shift + enter
.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", "In this case, it's like the jeans are suspended with **two identical cables on both sides**.Figure 2: Forces and angle 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", "Using again Newton's First Law of Motion ([derivations in this slide deck](figs/Physics-slides.pdf)), we can find the mass of the counterweight: \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",
"