{ "metadata": { "kernelspec": { "name": "python", "display_name": "Python (Pyodide)", "language": "python" }, "language_info": { "codemirror_mode": { "name": "python", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8" } }, "nbformat_minor": 5, "nbformat": 4, "cells": [ { "id": "8a6206e1-9145-471f-b7cd-f0f806e1268a", "cell_type": "code", "source": "%pip install ipywidgets", "metadata": { "trusted": true }, "outputs": [], "execution_count": 1 }, { "id": "95998bcd-2b01-4f44-bd8a-04182aefbb53", "cell_type": "code", "source": "%pip install https://dharmatech.github.io/github-pages-test/combine_equations-0.1.37-py3-none-any.whl", "metadata": { "trusted": true }, "outputs": [], "execution_count": 2 }, { "id": "98a9ae66-88b8-496b-87aa-6ea6a490767e", "cell_type": "code", "source": "# Import required modules\nfrom combine_equations.equation_gui_jupyter import show_equation_gui_jupyter\nfrom combine_equations.kinematics_states import make_states_model, kinematics_fundamental\nfrom combine_equations.display_equations import *\nfrom combine_equations.solve_and_display import *\nfrom sympy.physics.units import m, s\n", "metadata": { "trusted": true }, "outputs": [], "execution_count": 14 }, { "id": "7d88a167-bbdf-4706-8d13-b3bb6d88e125", "cell_type": "markdown", "source": "### A Fast Pitch\n \nThe fastest measured pitched baseball\nleft the pitcher’s hand at a speed of 45.0 m/s.\n \nIf the pitcher was in contact with the ball\nover a distance of 1.50 m \nand produced constant acceleration,\n \n(a) what acceleration did he give the ball, and\n \n(b) how much time did it take him to pitch it?", "metadata": {} }, { "id": "7f0b9f09-5038-44c8-91d0-916ddec1ddf3", "cell_type": "code", "source": "# Create model for baseball with 2 states\nb = make_states_model(\"b\", 2) # baseball with 2 states\nb0, b1 = b.states # initial and final states\nb01 = b.edges[0] # the interval between states\n\n# Generate fundamental kinematic equations for x-axis\neqs = kinematics_fundamental(b, axes=['x'])", "metadata": { "trusted": true }, "outputs": [], "execution_count": 8 }, { "id": "56894709-74b3-4834-93e3-7b7b01127cab", "cell_type": "code", "source": "# Define known values\nvalues = {}\nvalues[b0.pos.x] = 0 * m # starts at origin\nvalues[b1.pos.x] = 1.50 * m # ends at 1.5 m\nvalues[b0.vel.x] = 0 * m/s # starts from rest\nvalues[b1.vel.x] = 45.0 * m/s # final velocity\nvalues[b0.t] = 0 * s # time starts at 0\n\n# Target variable (what we want to find)\nwant = b01.a.x # acceleration", "metadata": { "trusted": true }, "outputs": [], "execution_count": 9 }, { "id": "c74886ff-1702-45ae-84f4-b66f14528ff9", "cell_type": "code", "source": "display_equations_(eqs, values, want=b01.a.x)", "metadata": { "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": "dt_b_0_1 = -\u001b[32mb_0_t\u001b[0m + b_1_t\nv_av_x_b_0_1 = (-\u001b[32mb_0_x\u001b[0m + \u001b[32mb_1_x\u001b[0m)/dt_b_0_1\n\u001b[31ma_x_b_0_1\u001b[0m = (-\u001b[32mb_0_v_x\u001b[0m + \u001b[32mb_1_v_x\u001b[0m)/dt_b_0_1\nv_av_x_b_0_1 = \u001b[32mb_0_v_x\u001b[0m/2 + \u001b[32mb_1_v_x\u001b[0m/2\n" } ], "execution_count": 12 }, { "id": "0943d317-c37a-4625-96c1-dd96b9b64c39", "cell_type": "code", "source": "solve_and_display_(eqs, values, want=b01.a.x)", "metadata": { "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": "Solving for unknowns: [b_1_t, a_x_b_0_1, dt_b_0_1, v_av_x_b_0_1]\n\u001b[31ma_x_b_0_1\u001b[0m = (\u001b[32mb_0_v_x\u001b[0m - \u001b[32mb_1_v_x\u001b[0m)*(\u001b[32mb_0_v_x\u001b[0m + \u001b[32mb_1_v_x\u001b[0m)/(2*(\u001b[32mb_0_x\u001b[0m - \u001b[32mb_1_x\u001b[0m))\n\u001b[31ma_x_b_0_1\u001b[0m = 675.0*meter/second**2\n" } ], "execution_count": 15 }, { "id": "4d31228f-ac5b-4fed-988d-3f092d060522", "cell_type": "code", "source": "display_equations_(eqs, values, want=b01.dt)", "metadata": { "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": "\u001b[31mdt_b_0_1\u001b[0m = -\u001b[32mb_0_t\u001b[0m + b_1_t\nv_av_x_b_0_1 = (-\u001b[32mb_0_x\u001b[0m + \u001b[32mb_1_x\u001b[0m)/\u001b[31mdt_b_0_1\u001b[0m\na_x_b_0_1 = (-\u001b[32mb_0_v_x\u001b[0m + \u001b[32mb_1_v_x\u001b[0m)/\u001b[31mdt_b_0_1\u001b[0m\nv_av_x_b_0_1 = \u001b[32mb_0_v_x\u001b[0m/2 + \u001b[32mb_1_v_x\u001b[0m/2\n" } ], "execution_count": 16 }, { "id": "b27e116f-ada7-4fc1-8f0c-1b4a2395d53b", "cell_type": "code", "source": "solve_and_display_(eqs, values, want=b01.dt)", "metadata": { "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": "Solving for unknowns: [b_1_t, a_x_b_0_1, dt_b_0_1, v_av_x_b_0_1]\n\u001b[31mdt_b_0_1\u001b[0m = 2*(-\u001b[32mb_0_x\u001b[0m + \u001b[32mb_1_x\u001b[0m)/(\u001b[32mb_0_v_x\u001b[0m + \u001b[32mb_1_v_x\u001b[0m)\n\u001b[31mdt_b_0_1\u001b[0m = 0.0666666666666667*second\n" } ], "execution_count": 17 }, { "id": "ae5e6963-eec6-43d2-a309-9c04a09e8a2e", "cell_type": "code", "source": "gui = show_equation_gui_jupyter(eqs, values=values, want=b01.a.x)", "metadata": { "trusted": true }, "outputs": [ { "output_type": "display_data", "data": { "text/plain": "VBox(children=(VBox(children=(HTML(value=\"