{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from resonance.linear_systems import SimplePendulumSystem" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "sys = SimplePendulumSystem()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'pendulum_mass': 0.0, 'pendulum_length': 0.0, 'acc_due_to_gravity': 0.0}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.constants" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "_SingleDoFCoordinatesDict([('angle', 0.0)])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.coordinates" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "_SingleDoFCoordinatesDict([('angle_vel', 0.0)])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.speeds" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.coordinates['angle']" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "sys.constants['pendulum_mass'] = 1.0 # kg\n", "sys.constants['pendulum_length'] = 1.0 # m\n", "sys.constants['acc_due_to_gravity'] = 9.81 # m/s**2" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "sys.coordinates['angle'] = np.deg2rad(10.0)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'pendulum_mass': 1.0, 'pendulum_length': 1.0, 'acc_due_to_gravity': 9.81}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.constants" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "_SingleDoFCoordinatesDict([('angle', 0.17453292519943295)])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.coordinates" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def calc_x(pendulum_length, angle):\n", " return pendulum_length * np.sin(angle)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "def calc_y(pendulum_length, angle):\n", " return pendulum_length * np.cos(angle)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.measurements" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "sys.add_measurement('x', calc_x)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'x': 0.17364817766693033}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.measurements" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "sys.add_measurement('y', calc_y)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'x': 0.17364817766693033, 'y': 0.984807753012208}" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.measurements" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.17364817766693033" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.measurements['x']" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "sys.coordinates['angle'] = np.deg2rad(20.0)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'x': 0.3420201433256687, 'y': 0.9396926207859084}" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sys.measurements" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "traj = sys.free_response(2.0)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
angleangle_accangle_velxy
time
0.000.349066-3.4243360.0000000.3420200.939693
0.010.348895-3.422656-0.0342380.3418590.939751
0.020.348381-3.417620-0.0684420.3413770.939927
0.030.347526-3.409230-0.1025790.3405730.940218
0.040.346330-3.397497-0.1366150.3394480.940625
..................
1.960.345439-3.3887540.1572010.3386090.940927
1.970.346841-3.4025100.1232420.3399290.940451
1.980.347903-3.4129300.0891620.3409270.940090
1.990.348624-3.4200010.0549940.3416050.939844
2.000.349003-3.4237180.0207730.3419610.939714
\n", "

201 rows × 5 columns

\n", "
" ], "text/plain": [ " angle angle_acc angle_vel x y\n", "time \n", "0.00 0.349066 -3.424336 0.000000 0.342020 0.939693\n", "0.01 0.348895 -3.422656 -0.034238 0.341859 0.939751\n", "0.02 0.348381 -3.417620 -0.068442 0.341377 0.939927\n", "0.03 0.347526 -3.409230 -0.102579 0.340573 0.940218\n", "0.04 0.346330 -3.397497 -0.136615 0.339448 0.940625\n", "... ... ... ... ... ...\n", "1.96 0.345439 -3.388754 0.157201 0.338609 0.940927\n", "1.97 0.346841 -3.402510 0.123242 0.339929 0.940451\n", "1.98 0.347903 -3.412930 0.089162 0.340927 0.940090\n", "1.99 0.348624 -3.420001 0.054994 0.341605 0.939844\n", "2.00 0.349003 -3.423718 0.020773 0.341961 0.939714\n", "\n", "[201 rows x 5 columns]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "traj" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f51c7acaf572468aa2e2e9a6266bb3a1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "array([,\n", " ,\n", " ,\n", " ,\n", " ],\n", " dtype=object)" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%matplotlib widget\n", "traj.plot(subplots=True)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mSignature:\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfree_response\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfinal_time\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minitial_time\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msample_rate\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m\n", "Returns a data frame with monotonic time values as the index and\n", "columns for each coordinate and measurement at the time value for that\n", "row. Note that this data frame is stored on the system as the variable\n", "``result`` until this method is called again, which will overwrite it.\n", "\n", "Parameters\n", "==========\n", "final_time : float\n", " A value of time in seconds corresponding to the end of the\n", " simulation.\n", "initial_time : float, optional\n", " A value of time in seconds corresponding to the start of the\n", " simulation.\n", "sample_rate : integer, optional\n", " The sample rate of the simulation in Hertz (samples per second).\n", " The time values will be reported at the initial time and final\n", " time, i.e. inclusive, along with times space equally based on the\n", " sample rate.\n", "\n", "Returns\n", "=======\n", "df : pandas.DataFrame\n", " A data frame indexed by time with all of the coordinates and\n", " measurements as columns.\n", "\u001b[0;31mFile:\u001b[0m /opt/conda/lib/python3.6/site-packages/resonance/system.py\n", "\u001b[0;31mType:\u001b[0m method\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sys.free_response?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7" } }, "nbformat": 4, "nbformat_minor": 4 }