Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/chap22.py
Views: 531
from modsim import *12params = Params(3x = 0, # m4y = 1, # m5angle = 45, # degree6speed = 40, # m / s78mass = 145e-3, # kg9diameter = 73e-3, # m10C_d = 0.33, # dimensionless1112rho = 1.2, # kg/m**313g = 9.8, # m/s**214t_end = 10, # s15)1617from modsim import *1819from numpy import pi, deg2rad2021def make_system(params):2223# convert angle to radians24theta = deg2rad(params.angle)2526# compute x and y components of velocity27vx, vy = pol2cart(theta, params.speed)2829# make the initial state30init = State(x=params.x, y=params.y, vx=vx, vy=vy)3132# compute the frontal area33area = pi * (params.diameter/2)**23435return System(params,36init = init,37area = area)3839from modsim import *4041def drag_force(V, system):42rho, C_d, area = system.rho, system.C_d, system.area4344mag = rho * vector_mag(V)**2 * C_d * area / 245direction = -vector_hat(V)46f_drag = mag * direction47return f_drag4849from modsim import *5051def slope_func(t, state, system):52x, y, vx, vy = state53mass, g = system.mass, system.g5455V = Vector(vx, vy)56a_drag = drag_force(V, system) / mass57a_grav = g * Vector(0, -1)5859A = a_grav + a_drag6061return V.x, V.y, A.x, A.y6263from modsim import *6465def event_func(t, state, system):66x, y, vx, vy = state67return y68697071