In [1]:
from resonance.linear_systems import SimplePendulumSystem
In [2]:
sys = SimplePendulumSystem()
In [3]:
sys.constants
Out[3]:
{'pendulum_mass': 0.0, 'pendulum_length': 0.0, 'acc_due_to_gravity': 0.0}
In [4]:
sys.coordinates
Out[4]:
_SingleDoFCoordinatesDict([('angle', 0.0)])
In [5]:
sys.speeds
Out[5]:
_SingleDoFCoordinatesDict([('angle_vel', 0.0)])
In [6]:
sys.coordinates['angle']
Out[6]:
0.0
In [7]:
sys.constants['pendulum_mass'] = 1.0  # kg
sys.constants['pendulum_length'] = 1.0  # m
sys.constants['acc_due_to_gravity'] = 9.81  # m/s**2
In [8]:
import numpy as np
In [9]:
sys.coordinates['angle'] = np.deg2rad(10.0)
In [10]:
sys.constants
Out[10]:
{'pendulum_mass': 1.0, 'pendulum_length': 1.0, 'acc_due_to_gravity': 9.81}
In [11]:
sys.coordinates
Out[11]:
_SingleDoFCoordinatesDict([('angle', 0.17453292519943295)])
In [12]:
def calc_x(pendulum_length, angle):
    return pendulum_length * np.sin(angle)
In [13]:
def calc_y(pendulum_length, angle):
    return pendulum_length * np.cos(angle)
In [14]:
sys.measurements
Out[14]:
{}
In [15]:
sys.add_measurement('x', calc_x)
In [16]:
sys.measurements
Out[16]:
{'x': 0.17364817766693033}
In [17]:
sys.add_measurement('y', calc_y)
In [18]:
sys.measurements
Out[18]:
{'x': 0.17364817766693033, 'y': 0.984807753012208}
In [19]:
sys.measurements['x']
Out[19]:
0.17364817766693033
In [20]:
sys.coordinates['angle'] = np.deg2rad(20.0)
In [21]:
sys.measurements
Out[21]:
{'x': 0.3420201433256687, 'y': 0.9396926207859084}
In [22]:
traj = sys.free_response(2.0)
In [23]:
traj
Out[23]:
angle angle_acc angle_vel x y
time
0.00 0.349066 -3.424336 0.000000 0.342020 0.939693
0.01 0.348895 -3.422656 -0.034238 0.341859 0.939751
0.02 0.348381 -3.417620 -0.068442 0.341377 0.939927
0.03 0.347526 -3.409230 -0.102579 0.340573 0.940218
0.04 0.346330 -3.397497 -0.136615 0.339448 0.940625
... ... ... ... ... ...
1.96 0.345439 -3.388754 0.157201 0.338609 0.940927
1.97 0.346841 -3.402510 0.123242 0.339929 0.940451
1.98 0.347903 -3.412930 0.089162 0.340927 0.940090
1.99 0.348624 -3.420001 0.054994 0.341605 0.939844
2.00 0.349003 -3.423718 0.020773 0.341961 0.939714

201 rows × 5 columns

In [24]:
%matplotlib widget
traj.plot(subplots=True)
Out[24]:
array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f29060c0b70>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f2906034048>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f2905fe4400>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f2905f97860>,
       <matplotlib.axes._subplots.AxesSubplot object at 0x7f2905fcacc0>],
      dtype=object)
In [25]:
sys.free_response?
Signature: sys.free_response(final_time, initial_time=0.0, sample_rate=100, **kwargs)
Docstring:
Returns a data frame with monotonic time values as the index and
columns for each coordinate and measurement at the time value for that
row. Note that this data frame is stored on the system as the variable
``result`` until this method is called again, which will overwrite it.

Parameters
==========
final_time : float
    A value of time in seconds corresponding to the end of the
    simulation.
initial_time : float, optional
    A value of time in seconds corresponding to the start of the
    simulation.
sample_rate : integer, optional
    The sample rate of the simulation in Hertz (samples per second).
    The time values will be reported at the initial time and final
    time, i.e. inclusive, along with times space equally based on the
    sample rate.

Returns
=======
df : pandas.DataFrame
    A data frame indexed by time with all of the coordinates and
    measurements as columns.
File:      /opt/conda/lib/python3.6/site-packages/resonance/system.py
Type:      method
In [ ]: