Sharedprojects / POI.ipynbOpen in CoCalc
Authors: Nabih Estefan, Maya Sivanandan
Views : 15
In [37]:
# Configure Jupyter so figures appear in the notebook %matplotlib inline # Configure Jupyter to display the assigned value after an assignment %config InteractiveShell.ast_node_interactivity='last_expr_or_assign' # import functions from the modsim.py module from modsim import * import math import numpy
In [38]:
m = UNITS.meter kg = UNITS.kilogram s = UNITS.second N = UNITS.newton radians = UNITS.radians
radian
In [63]:
def make_system(): length_string = 0.4 * m length_arm = 0.8 * m mass_poi = 127 * 10**-3 * kg mass_handle = 16 * 10**-3 * kg k = 'YAY wait, WTF, HOW DO I DO THIS? INFINITY? WHYYYYYYYYYYYYY' r1 = length_string r2 = length_string + length_arm TM = mass_poi + mass_handle poi = Vector(-r1, 0 * m) handle = (0 * m, 0 * m) poiV = Vector(0 * m / s, -3.443 * m / s) handleV = Vector(0 * m / s, 0 * m / s) g = -9.8 * m / s**2 init = State(poi=poi, poiV=poiV) return System(init=init, r1=r1, mass_poi=mass_poi, g=g, t_end= 0.73 * s)
In [ ]:
In [67]:
def slope_funcPt1(state, t, system): print(state) x = state.poi.x y = state.poi.y vx = state.poiV.x vy = state.poiV.y r1 = system.r1 g = system.g mass_poi = system.mass_poi #print(x,y, vx, vy) tension = (mass_poi * state.poiV.mag**2) / r1 ax = -(tension / mass_poi) * math.cos(state.poi.angle) ay = -(tension / mass_poi) * math.sin(state.poi.angle) dvxdt = ax dvydt = ay dxdt = vx dydt = vy print(dxdt, dydt, dvxdt, dvydt) return Vector(dxdt, dydt), Vector(dvxdt, dvydt)
In [65]:
system = make_system() slope_funcPt1(system.init, 0 * s, system)
poi [-0.4 meter, 0.0 meter] poiV [0.0 meter / second, -3.443 meter / second] dtype: object 0.0 meter / second -3.443 meter / second 29.6356225 meter / second ** 2 -3.629317023536428e-15 meter / second ** 2
(array([ 0. , -3.443]) <Unit('meter / second')>, array([ 2.96356225e+01, -3.62931702e-15]) <Unit('meter / second ** 2')>)
In [66]:
results, details = run_ode_solver(system, slope_funcPt1) results
poi [-0.4 meter, 0.0 meter] poiV [0.0 meter / second, -3.443 meter / second] Name: 0, dtype: object 0.0 meter / second -3.443 meter / second 29.6356225 meter / second ** 2 -3.629317023536428e-15 meter / second ** 2 [<Quantity([-0.4 -0.01675593], 'meter')>, <Quantity([ 0.1442267 -3.443 ], 'meter / second')>]
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-66-4be5e8d779fe> in <module> ----> 1 results, details = run_ode_solver(system, slope_funcPt1) 2 results /srv/conda/envs/notebook/lib/python3.7/site-packages/modsim/modsim.py in run_ralston(system, slope_func, **options) 761 # evaluate the slopes at the two-thirds point 762 y_mid, t_mid = project(y1, t1, slopes1, 2 * dt / 3) --> 763 slopes2 = slope_func(y_mid, t_mid, system) 764 765 # compute the weighted sum of the slopes <ipython-input-64-ba080488544d> in slope_funcPt1(state, t, system) 3 print(state) 4 ----> 5 x = state.poi.x 6 y = state.poi.y 7 vx = state.poiV.x AttributeError: 'list' object has no attribute 'poi'
In [23]:
plot(results.poi.x, color = 'blue', label='x') plot(results.poi.y, color = 'green', label='y') plot(results.tension, color = 'red', label='tension')
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-23-4dba59581bc3> in <module> ----> 1 plot(results.poi.x, color = 'blue', label='x') 2 plot(results.poi.y, color = 'green', label='y') 3 plot(results.tension, color = 'red', label='tension') /srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name) 5177 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5178 return self[name] -> 5179 return object.__getattribute__(self, name) 5180 5181 def __setattr__(self, name, value): AttributeError: 'TimeSeries' object has no attribute 'x'
In [1]:
jupyter nbconvert --to pdf -- 'POI.ipynb'
File "<ipython-input-1-d9a26cb6d156>", line 1 jupyter nbconvert --to pdf -- 'POI.ipynb' ^ SyntaxError: invalid syntax
In [ ]: