{ "cells": [ { "cell_type": "markdown", "id": "5e8b080b-2139-4f3e-9347-f183c25ada3c", "metadata": {}, "source": [ "# Bouncing ball" ] }, { "cell_type": "markdown", "id": "919538f8-afd8-4573-a105-182a90900ed8", "metadata": {}, "source": [ "Consider a ball moving in a vertical direction, acceleration of gravity $g$, and bouncing elastically from a floor that oscillates harmonically, with the amplitude $a$ and frequency $\\omega$:\n", "\n", "$$h(t) = a \\sin(\\omega t) . $$\n", "\n", "The velocity of the floor,\n", "\n", "$$v_{floor} \\equiv \\frac{\\mathrm{d}h}{\\mathrm{d}t} = a \\omega \\cos(\\omega t) .$$ " ] }, { "cell_type": "markdown", "id": "e151ea40-f5cf-4c45-876f-75ff9bf1f7fe", "metadata": {}, "source": [ "Since the collision ball-floor is elastic, the velocities of the ball just before and after the collision are related as follows:\n", "\n", "$$v_{after} = -v_{before} + 2 v_{floor} = -v_{before} + 2 a \\omega \\cos(\\omega t), $$\n", "\n", "where $t$ is the instance of a collision, and $v_{floor}$ is the velocity of the floor at the instance of collision." ] }, { "cell_type": "markdown", "id": "64f0fede-361e-4227-9b1d-78fea3f5b7e0", "metadata": {}, "source": [ "The motion of the ball outside of the instances of collision is the motion with the constant acceleration $-g$:\n", "\n", "$$\\frac{\\mathrm{d}^2 y}{\\mathrm{d}t^2} = -g,$$\n", "\n", "or \n", "\n", "$$\\frac{\\mathrm{d}y}{\\mathrm{d}t} = v, \\quad \\frac{\\mathrm{d}v}{\\mathrm{d}t} = -g.$$\n", "\n", "Here $v$ is the velocity of the ball." ] }, { "cell_type": "markdown", "id": "8d0a758a-9b41-40c7-b2e8-6d257305a7c8", "metadata": {}, "source": [ "Let's introduce dimensionless units:\n", "\n", "$$Y = \\frac{y}{a}, \\quad \\tau = \\omega t .$$" ] }, { "cell_type": "markdown", "id": "f8fe2384-d907-4cf4-a3fe-2066ea279446", "metadata": {}, "source": [ "In the new variables $Y$, $\\tau$, the equation of motion are as follows:\n", "\n", "$$\\frac{\\mathrm{d}^2 Y}{\\mathrm{d}\\tau^2} = -G,$$\n", "\n", "or\n", "\n", "$$\\frac{\\mathrm{d}Y}{\\mathrm{d}\\tau} = V, \\quad \\frac{\\mathrm{d}V}{\\mathrm{d}\\tau} = -G,$$\n", "\n", "where \n", "\n", "$$G = \\frac{g}{a \\omega^2}$$\n", "\n", "is the only dimensional parameter of the problem, and\n", "\n", "$$V = \\frac{v}{a \\omega}$$\n", "\n", "is the dimensionless velocity of the ball." ] }, { "cell_type": "markdown", "id": "ee9fb745-92b1-4961-8f7d-0644190a4ad3", "metadata": {}, "source": [ "The conditions of the floor-ball collusion in the dimensionless units are as follows:\n", "\n", "$$Y_{collision} = \\sin(\\tau), \\quad V_{after} = -V_{before} + 2 \\cos(\\tau). $$" ] }, { "cell_type": "markdown", "id": "5f0fa274-9c73-4eff-9571-1d3c069ec7cd", "metadata": {}, "source": [ "The energy of the ball, $e$, is changing during the collisions. The dimensionless energy of the ball is\n", "\n", "$$E \\equiv \\frac{e}{m a^2 \\omega^2} = G Y + \\frac{V^2}{2}. $$" ] }, { "cell_type": "code", "execution_count": null, "id": "7dd760ce-a94c-455c-927a-bba3944eabb1", "metadata": {}, "outputs": [], "source": [ "\n", "using OrdinaryDiffEqTsit5\n", "using PyPlot" ] }, { "cell_type": "markdown", "id": "5d23d5ec-0eb0-47ea-a765-d506dfdfdeea", "metadata": {}, "source": [ "The right hand side of the equation of motion, written in a vector form:" ] }, { "cell_type": "code", "execution_count": null, "id": "8a1c9df3-9a8a-4bc8-b980-d7ee362b59e3", "metadata": {}, "outputs": [], "source": [ "\n", "function bouncingball!(dudt, u, G, tau)\n", " dudt[1] = u[2]\n", " dudt[2] = -G\n", "end" ] }, { "cell_type": "markdown", "id": "15718a60-0a82-4035-b9e2-018c88f4f8df", "metadata": {}, "source": [ "The condition of collision ball-floor: $u[1] = sin(t)$, or $u[1] - sin(t) = 0$. " ] }, { "cell_type": "code", "execution_count": null, "id": "8781bc0a-441d-4ddc-b7e0-2e0b113e2139", "metadata": {}, "outputs": [], "source": [ "\n", "function condition(u, t, integrator)\n", " u[1] - sin(t)\n", "end" ] }, { "cell_type": "markdown", "id": "b8703a81-5398-4158-8151-8f6c4c84ac7d", "metadata": {}, "source": [ "Change the velocity of the ball at the instant of collision:" ] }, { "cell_type": "code", "execution_count": null, "id": "af203a92-33e7-4efc-a330-03276efbfa94", "metadata": {}, "outputs": [], "source": [ "\n", "function affect!(integrator)\n", " integrator.u[2] = -integrator.u[2] + 2*cos(integrator.t)\n", "end" ] }, { "cell_type": "markdown", "id": "f4f9fafa-f7fa-4ffd-b60c-1d7b39d8ddf0", "metadata": {}, "source": [ "Callback:" ] }, { "cell_type": "code", "execution_count": null, "id": "bb114e0b-60aa-43b6-b582-d78db3eab7cb", "metadata": {}, "outputs": [], "source": [ "\n", "cb = ContinuousCallback(condition, affect!)" ] }, { "cell_type": "markdown", "id": "3ab5254d-c558-4079-9d77-c922c9649b90", "metadata": {}, "source": [ "Initial conditions and parameters:" ] }, { "cell_type": "code", "execution_count": null, "id": "a6c63c8d-7e96-48da-8246-ca9fa71c362b", "metadata": {}, "outputs": [], "source": [ "\n", "u0 = [0.0001, 0.0]\n", "G = 1.0\n", "tspan = (0.0, 100.0);" ] }, { "cell_type": "markdown", "id": "23f0c6e4-e630-461c-a577-cc21b0ac703c", "metadata": {}, "source": [ "Problem statement:" ] }, { "cell_type": "code", "execution_count": null, "id": "fdcf093f-2ed1-44e3-be33-c4a401bafcfc", "metadata": {}, "outputs": [], "source": [ "\n", "prob = ODEProblem(bouncingball!, u0, tspan, G)" ] }, { "cell_type": "markdown", "id": "da632b98-6940-4176-bc28-cf788277088e", "metadata": {}, "source": [ "Numerical solution:" ] }, { "cell_type": "code", "execution_count": null, "id": "431f08a5-0149-4499-9c43-547b85fb72fc", "metadata": {}, "outputs": [], "source": [ "\n", "sol = solve(prob, Tsit5(), callback=cb, dtmax=0.1);" ] }, { "cell_type": "markdown", "id": "5da8b181-e873-4cd4-ba48-45c55144016a", "metadata": {}, "source": [ "Plot the motion of the ball and the floor:" ] }, { "cell_type": "code", "execution_count": null, "id": "df023e77-3321-41c5-838a-067fc222c0e1", "metadata": {}, "outputs": [], "source": [ "\n", "plot(sol.t, sol[1,:], label=\"Ball\")\n", "plot(sol.t, sin.(sol.t), label=\"Floor\")\n", "grid(true)\n", "xlabel(\"time\")\n", "ylabel(\"height\")\n", "legend()\n", "title(\"Elastic ball bouncing on an oscillating floor\");" ] }, { "cell_type": "markdown", "id": "56bd4cf1-24b6-482c-85bf-470d36acd943", "metadata": {}, "source": [ "Energy of the ball:" ] }, { "cell_type": "code", "execution_count": null, "id": "395e4a72-41d6-4aa1-be05-60b85670e123", "metadata": {}, "outputs": [], "source": [ "\n", "function energy(sol, G)\n", " G * sol[1, :] .+ 0.5 .* (sol[2, :]) .^ 2\n", "end" ] }, { "cell_type": "code", "execution_count": null, "id": "645ce892-3bca-40a0-b574-fba26f273764", "metadata": {}, "outputs": [], "source": [ "\n", "en = energy(sol, G);" ] }, { "cell_type": "code", "execution_count": null, "id": "81c83f4e-8bc3-44ef-865a-07313d7d7b4e", "metadata": {}, "outputs": [], "source": [ "\n", "plot(sol.t, en)\n", "grid(true)\n", "xlabel(\"time\")\n", "ylabel(\"energy\")\n", "title(\"Elastic ball bouncing on an oscillating floor\");" ] }, { "cell_type": "markdown", "id": "7b596a4f-83ac-41ec-a8fb-809a18b05922", "metadata": {}, "source": [ "Notice that the energy is changing during the collisions, but it is conserved between the collisions. " ] }, { "cell_type": "code", "execution_count": null, "id": "5a9b431d-3a45-46d9-a92d-3cc47cdbe57f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.10.5", "language": "julia", "name": "julia-1.10" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.10.5" } }, "nbformat": 4, "nbformat_minor": 5 }