|
6 | 6 | "source": [ |
7 | 7 | "# Modeling and Simulation in Python\n", |
8 | 8 | "\n", |
9 | | - "Chapter 10 Example: Spiderman\n", |
| 9 | + "Chapter 10 Example: Spider-Man\n", |
10 | 10 | "\n", |
11 | 11 | "Copyright 2017 Allen Downey\n", |
12 | 12 | "\n", |
|
80 | 80 | "\n", |
81 | 81 | "Initially, Spider-Man is at the top of a nearby builing. I'll create a `Condition` object to contain the quantities we'll need:\n", |
82 | 82 | "\n", |
83 | | - "1. According to [the Spider-Man Wiki](http://spiderman.wikia.com/wiki/Peter_Parker_(Earth-616)) Spider-Man weighs 76 kg.\n", |
| 83 | + "1. According to [the Spider-Man Wiki](http://spiderman.wikia.com/wiki/Peter_Parker_(Earth-616), Spider-Man weighs 76 kg.\n", |
84 | 84 | "\n", |
85 | 85 | "2. Let's assume his terminal velocity is 60 m/s.\n", |
86 | 86 | "\n", |
|
103 | 103 | " area = 1 * m**2,\n", |
104 | 104 | " rho = 1.2 * kg/m**3,\n", |
105 | 105 | " v_term = 60 * m / s,\n", |
106 | | - " duration = 60 * s,\n", |
| 106 | + " duration = 30 * s,\n", |
107 | 107 | " length = 100 * m,\n", |
108 | 108 | " angle = (270 - 45) * degree,\n", |
109 | 109 | " k = 20 * N / m)" |
|
138 | 138 | " \"\"\"\n", |
139 | 139 | " unpack(condition)\n", |
140 | 140 | " \n", |
141 | | - " A = Vector(0, height)\n", |
| 141 | + " H = Vector(0, height)\n", |
142 | 142 | " \n", |
143 | 143 | " theta = angle.to(radian)\n", |
144 | 144 | " x, y = pol2cart(theta, length)\n", |
145 | 145 | " L = Vector(x, y)\n", |
146 | | - " P = A + L\n", |
| 146 | + " P = H + L\n", |
147 | 147 | " V = Vector(0*m/s, 0*m/s)\n", |
148 | 148 | " \n", |
149 | 149 | " init = State(x=P.x, y=P.y, vx=V.x, vy=V.y)\n", |
|
153 | 153 | " \n", |
154 | 154 | " return System(init=init, g=g, mass=mass, rho=rho,\n", |
155 | 155 | " C_d=C_d, area=area, length=length,\n", |
156 | | - " A=A, k=k, ts=ts)" |
| 156 | + " H=H, k=k, ts=ts)" |
157 | 157 | ] |
158 | 158 | }, |
159 | 159 | { |
|
208 | 208 | "\n", |
209 | 209 | " P = Vector(x, y)\n", |
210 | 210 | " V = Vector(vx, vy)\n", |
211 | | - " L = P - A\n", |
| 211 | + " L = P - H\n", |
212 | 212 | " \n", |
213 | 213 | " f_spring = -k * (L.mag - length) * L.hat()\n", |
214 | 214 | " a_spring = f_spring / mass\n", |
|
251 | 251 | { |
252 | 252 | "cell_type": "code", |
253 | 253 | "execution_count": null, |
254 | | - "metadata": { |
255 | | - "collapsed": true |
256 | | - }, |
| 254 | + "metadata": {}, |
257 | 255 | "outputs": [], |
258 | 256 | "source": [ |
259 | | - "run_odeint(system, slope_func)" |
| 257 | + "%time run_odeint(system, slope_func)" |
260 | 258 | ] |
261 | 259 | }, |
262 | 260 | { |
|
372 | 370 | "newfig()\n", |
373 | 371 | "decorate(xlabel='x position (m)',\n", |
374 | 372 | " ylabel='y position (m)',\n", |
375 | | - " xlim=[-105, 105],\n", |
| 373 | + " xlim=[-80, 80],\n", |
376 | 374 | " ylim=[0, 381],\n", |
377 | 375 | " legend=False)\n", |
378 | 376 | "\n", |
|
0 commit comments