diff --git a/PredictionQuestion/FreeFall-withCode.ipynb b/PredictionQuestion/FreeFall-withCode.ipynb index 6ce149d..83c0ef0 100644 --- a/PredictionQuestion/FreeFall-withCode.ipynb +++ b/PredictionQuestion/FreeFall-withCode.ipynb @@ -1,382 +1,460 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook is about demonstrating:\n", "* prediction questions\n", "* observation questions\n", "\n", "The example chosen is voluntarily *simple* so that anyone can understand what is illustrated and focus the pedagogical features of the example." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Free fall\n", "\n", "An object is dropped from a given height with no initial velocity. We are interested in the movement from the object in the case where *resistance from the air is ignored*.\n", "\n", "1. Answer the following prediction questions - be sure to write down your answer on a piece of paper:\n", " * Which object would reach the ground first: a bowling ball (5 kg) or a tennis ball (0.05 kg)?\n", " * Why? Describe in words your explanation for this behavior.\n", " * Sketch your prediction for the *height* of the object as a function of time. Describe in words what this graph means.\n", " * Sketch your prediction for the *velocity* of the object as a function of time. Describe in words what this graph means.\n", " * Sketch your prediction for the *acceleartion* of the object as a function of time. Describe in words what this graph means.\n", "\n", "\n", "2. Run the demo and answer the following observation questions :\n", " * When does the bowling ball reaches the ground (time in seconds)?\n", " * When does the tennis ball reaches the ground (time in seconds)?\n", " * When does the ostrich feather reaches the ground (time in seconds)?\n", "\n", "\n", "3. Compare the explanation provided in this notebook with your own explanation.\n", "\n", "To be fully convinced, look at the video at the end of this notebook!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# Demo" + "# Let's setup a virtual experiment" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ + "%matplotlib inline\n", "import numpy as np\n", "import pandas\n", "\n", "from ipywidgets import interact, interactive, fixed, interact_manual\n", "from ipywidgets import HBox, VBox, Label\n", "import ipywidgets as widgets\n", "\n", "import matplotlib.pyplot as plt\n", - "%matplotlib inline\n", "plt.style.use('seaborn-whitegrid') # global style for plotting" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, let's create the list of objects with which we can experiment.\n", "\n", "Objects come with a name, a mass (in $kg$) and a color for identifying them in the graphical display." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
masscolor
name
Bowling ball5.000#DC143C
Tennis ball0.050#2E8B57
Ostrich feather0.005#483D8B
\n", + "
" + ], + "text/plain": [ + " mass color\n", + "name \n", + "Bowling ball 5.000 #DC143C\n", + "Tennis ball 0.050 #2E8B57\n", + "Ostrich feather 0.005 #483D8B" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Types of objects we have with their mass\n", "objects = [{\n", " 'name':'Bowling ball',\n", " 'mass':5.0,\n", " 'color':'#DC143C'\n", " },{\n", " 'name':'Tennis ball',\n", " 'mass':0.05,\n", " 'color':'#2E8B57'\n", " },{ \n", " 'name':'Ostrich feather',\n", " 'mass':0.005,\n", " 'color':'#483D8B'\n", "}]\n", "objects_list = pandas.DataFrame(objects, columns = ['name', 'mass', 'color'])\n", "objects_list.set_index('name', inplace=True) # Index objects by their name to find them easily after\n", "objects_list" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then let's define the parameters of our problem:\n", "* gravity\n", "* initial conditions: initial height (in $m$) and initial velocity (in $m.s^{-1}$)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Parameters of the problem\n", "g = 9.81 # gravity in m/s2\n", "\n", "# Initial conditions\n", "h_0 = 5 # initial height in m\n", "v_0 = 0 # initial velocity in m/s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the movement of our objects in time we need to define a time interval. " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# Time space\n", + "# Time scale\n", "t = np.linspace(0,3,25) # time scale from 0 to x seconds, with n points in the interval" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then we define three functions which compute the movement of our objects in free fall on our time interval." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Functions representing the equations of the movement as functions of time and the problem parameters\n", "def accel_time (t, m, h_0, v_0):\n", " return [-g]*t.size # returning a list of same length as the time list filled with -g\n", "\n", "def veloc_time (t, m, h_0, v_0):\n", " return -g*t+v_0 \n", "\n", "def height_time (t, m, h_0, v_0):\n", " return -0.5*g*(t**2)+v_0*t+h_0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we create an interactive graph which will plot the equations of the objects depending on the parameters that the user selects." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "59ef305e81ad4037b4e7b67a06b4721a", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(Output(), HBox(children=(VBox(children=(HBox(children=(Label(value='Choice of object(s):'), Sel…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "# parameters for sliders\n", "h_min = 0\n", "h_max = 10\n", "v_min = 0\n", "v_max = 10\n", "\n", "\n", "# IHM input elements\n", "h_label = Label('Initial height ($m$):')\n", "h_widget = widgets.FloatSlider(min=h_min,max=h_max,step=1,value=h_0)\n", "h_input = HBox([h_label, h_widget])\n", "\n", "v_label = Label('Initial velocity ($m.s^{-1}$):')\n", "v_widget = widgets.FloatSlider(min=v_min,max=v_max,step=1,value=v_0)\n", "v_input = HBox([v_label, v_widget])\n", "\n", "obj_m_label = Label('Choice of object(s):')\n", "obj_m_widget = widgets.SelectMultiple(\n", " options = objects_list.index,\n", " value = [objects_list.index[0],], # tuple(objects_list['name'])\n", " disabled = False\n", ")\n", "obj_m_input = HBox([obj_m_label, obj_m_widget])\n", "\n", "# IHM output elements\n", "obj_m_output = widgets.Output()\n", "graph_output = widgets.Output()\n", "\n", "# Display updated output function\n", "def display_updated_output(h_0, v_0, objs):\n", " # Clear outputs\n", " graph_output.clear_output(wait=True)\n", " obj_m_output.clear_output(wait=True)\n", " \n", " # Create the figure\n", " fig, ax = plt.subplots(1, 3, sharex='col', figsize=(16, 4))\n", "\n", " # for each object selected (by name)\n", " for o in objs:\n", " # get mass\n", " m = objects_list.loc[objects_list.index == o]['mass'].item()\n", " # get color\n", " c = objects_list.loc[objects_list.index == o]['color'].item()\n", " \n", " \n", " # Recompute equations with parameters set by the user\n", " h_t = height_time(t, m, h_0, v_0)\n", " v_t = veloc_time(t, m, h_0, v_0)\n", " a_t = accel_time(t, m, h_0, v_0)\n", "\n", " # Plot equations\n", " ax[0].set_title('Height ($m$)')\n", " ax[0].plot(t, h_t, color=c, label=o)\n", " ax[0].set_ylim(bottom = 0) # limit y axis to values >= 0\n", "\n", " ax[1].set_title('Velocity ($m.s^{-1}$)')\n", " ax[1].plot(t, v_t, color=c, label=o)\n", "\n", " ax[2].set_title('Acceleration ($m.s^{-2}$)')\n", " ax[2].plot(t, a_t, color=c, label=o)\n", " \n", " # Display weight of object selected\n", " with obj_m_output:\n", " print(\"Weight of the object selected (kg): \", m)\n", "\n", " # Add time axis and legend\n", " for a in ax:\n", " a.set_xlabel('Time (s)')\n", " a.legend()\n", "\n", " fig.tight_layout()\n", " \n", " # Display graph \n", " with graph_output:\n", " plt.show()\n", " \n", "\n", "# Event handlers\n", "def h_event_handler(change):\n", " display_updated_output(change.new, v_widget.value, obj_m_widget.value)\n", "\n", "def v_event_handler(change):\n", " display_updated_output(h_widget.value, change.new, obj_m_widget.value)\n", "\n", "def obj_m_event_handler(change):\n", " display_updated_output(h_widget.value, v_widget.value, change.new) # obj_m_transform(change.new)\n", "\n", "\n", "# Linking widgets to handlers\n", "h_widget.observe(h_event_handler, names='value')\n", "v_widget.observe(v_event_handler, names='value')\n", "obj_m_widget.observe(obj_m_event_handler, names='value')\n", "\n", "#ihm = VBox([m_box, output_object, h_box, v_box, output_graph])\n", "# Organize layout \n", "ihm = VBox([graph_output,\n", " HBox([\n", " VBox([obj_m_input, obj_m_output]),\n", " VBox([h_input, v_input])])\n", " ])\n", "\n", "# Display whole interface with the graph already plotted\n", "display(ihm)\n", "display_updated_output(h_0, v_0, [objects_list.index[0],]) # objects_list['name']\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Explanation\n", "\n", "Let's draw a free body diagram and represent the forces applied on our object.\n", "\n", "![Free Body Diagram](Images/FBD-ball.png)\n", "\n", "If we ignore the friction from air, the only force applied on the object is the weight: $\\vec p = m \\vec g$\n", "\n", "From Newton's second law we can write: $\\sum \\vec F = m \\vec a$\n", "\n", "With the weight the only force we have we get: $\\vec p = m \\vec a$\n", "\n", "Using the expression of the weight: $m \\vec g = m \\vec a$\n", "\n", "Therefore the movement of the object is described by $\\vec a = \\vec g$.\n", "\n", "To get the equation of acceleration as a function of time, let's project onto our coordinate system: $a = -g$, therefore $a(t) = -g$.\n", "This means the ball is under **constant acceleration**\n", "\n", "From there we can get the equations for velocity and height by integrating successively:\n", "\n", "$\\left\\{\\begin{matrix} a(t) = -g \\\\ v(t) = -g\\,t + v_0 \\\\ h(t) = -\\frac{1}{2}\\,g\\,t^2 + v_0\\,t + h_0\\end{matrix}\\right. $\n", "\n", "With the following parameters:\n", "* the initial height $h_0$ from which the object is dropped\n", "* the initial velocity of the object $v_0$, with $v_0 = 0$ when the object is dropped with no initial velocity\n", "* and of course the acceleration due to gravity $g$\n", "\n", "We see clearly that **the mass $m$ of the object plays no role at all in the movement**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# And how does that look in real life?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%HTML\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Additional questions: role of the initial velocity\n", "\n", - "Choose one object. Which initial velocity is it necessary to give it so that it reaches the ground at $t = 2.5 s$?\n", + "Choose one object and drop it from 7 meter above the ground. Which initial velocity is it necessary to give it so that it reaches the ground at $t = 2.5 s$?\n", "\n", "Choose one object and give it an initial velocity.\n", "* When does it reaches its maximum height?\n", "* What is its velocity at that moment? Why?\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Other documents\n", "\n", "https://www.rentech.com.tr/wp-content/uploads/2017/09/PWV-06-ball_toss.pdf\n", "\n", "https://opentextbc.ca/physicstestbook2/chapter/falling-objects/" ] } ], "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.8" } }, "nbformat": 4, "nbformat_minor": 2 } diff --git a/PredictionQuestion/FreeFall.ipynb b/PredictionQuestion/FreeFall.ipynb index b675ebd..85d4ed6 100644 --- a/PredictionQuestion/FreeFall.ipynb +++ b/PredictionQuestion/FreeFall.ipynb @@ -1,263 +1,265 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook is about demonstrating:\n", "* prediction questions\n", "* observation questions\n", "* hiding code\n", "\n", "The example chosen is voluntarily *simple* so that anyone can understand what is illustrated and focus the pedagogical features of the example." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Free fall\n", "\n", "## The problem\n", + "We **drop** an object from a given height with **no initial velocity**. Just like an apple would fall from a tree.\n", "\n", - "We drop an object from a given height with no initial velocity. \n", + "![apple_dropping](https://cdn4.iconfinder.com/data/icons/brainy-icons-free-36-science-and-education-icons/64/apple_64.png)\n", "\n", - "We are interested in the movement from the object in the case where *resistance from the air is ignored*.\n", + "We will consider the movement of the object, **ignoring resistance from air**.\n", "\n", "## Questions\n", "\n", "**Answer the following questions _before_ using the virtual lab.**\n", "\n", "1. Which object would reach the ground first: a bowling ball (5 kg) or a tennis ball (0.05 kg)? Write down your answer in the cell below." ] }, { "cell_type": "raw", "metadata": {}, "source": [ "### Type your answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Why? In the cell below, describe in words your explanation for this behavior." ] }, { "cell_type": "raw", "metadata": {}, "source": [ "### Type your answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In physics, as in many disciplines, sketching your ideas can really help you figure out problems. \n", "It might be a good idea to take a piece of paper and sketch what you think the following variables will look like as a function of time:\n", "* the *height* of the object \n", "* the *velocity* of the object \n", "* the *acceleration* of the object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Virtual lab\n", "The virtual demonstration below illustrates the movement of different objects.\n", "\n", "Launch the virtual demonstration by executing the cell below, then *answer the questions below*." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "%run 'lib/virtuallab.py' ;" + "%matplotlib inline\n", + "from lib.virtuallab import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Use the interactive figure to answer the following questions.**\n", "\n", "Choose an initial height and an initial velocity, which will be the same for all the objects you will observe.\n", "\n", "1. When does the bowling ball reaches the ground (time in seconds)?" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "### Type your answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. When does the tennis ball reaches the ground (time in seconds)?" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "### Type your answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3. When does the ostrich feather reaches the ground (time in seconds)?" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "### Type your answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Actually, the interactive figure allows you to plot the movement of several objects simultaneously by maintaining the 'ctrl' key selected while clicking with your mouse on the objects you want to display.\n", "\n", "**Select several objects to display simultaneously.**\n", "\n", "What do you see?" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "### Type your answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What can you conclude from this first experiment?" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "### Type your answer here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Synthesis\n", "\n", "**Compare your own explanation with the explanation provided below**.\n", "\n", "\n", "\n", "If we ignore the friction from air, the only force applied on the object is the weight: $\\vec p = m \\vec g$\n", "\n", "From Newton's second law we can write: $\\sum \\vec F = m \\vec a$\n", "\n", "With the weight the only force on the object, we get: $\\vec p = m \\vec a$\n", "\n", "Using the expression of the weight: $m \\vec g = m \\vec a$\n", "\n", "Therefore the movement of the object is described by $\\vec a = \\vec g$.\n", "\n", "To get the equation of acceleration as a function of time, let's project onto our coordinate system: $a = -g$, therefore $a(t) = -g$.\n", "\n", "This means that the ball is under **constant acceleration**.\n", "\n", "From there we can get the equations for velocity and height by integrating successively:\n", "\n", "$\\left\\{\\begin{matrix} a(t) = -g \\\\ v(t) = -g\\,t + v_0 \\\\ h(t) = -\\frac{1}{2}\\,g\\,t^2 + v_0\\,t + h_0\\end{matrix}\\right. $\n", "\n", "With the following parameters:\n", "* the initial height $h_0$ from which the object is dropped\n", "* the initial velocity of the object $v_0$, with $v_0 = 0$ when the object is dropped with no initial velocity\n", "* and of course the acceleration due to gravity $g$\n", "\n", "We see clearly that **the mass $m$ of the object plays no role at all in the movement**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How does that look in real life?\n", "\n", "The following video demonstrates how a bowling ball and ostrich feathers fall in a vacuum chamber, thus illustrating how what we have seen so far looks in the real world." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%HTML\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How does the virtual lab work?\n", "\n", "You can have a look at the code of the virtual lab by [opening this python file](lib/virtuallab.py).\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Other resources on the web\n", "\n", "https://www.rentech.com.tr/wp-content/uploads/2017/09/PWV-06-ball_toss.pdf\n", "\n", "https://opentextbc.ca/physicstestbook2/chapter/falling-objects/\n", "\n", "http://www.physagreg.fr/mecanique/m12/M12-chute-libre-frottements.pdf" ] } ], "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.8" } }, "nbformat": 4, "nbformat_minor": 2 }