Skip to content

Commit befb7f3

Browse files
committed
Fixing lab 7
1 parent 3c5b897 commit befb7f3

1 file changed

Lines changed: 55 additions & 45 deletions

File tree

‎Week_7_simulation/Lab_7_simulating_quarter_car.ipynb‎

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "3c012c2f",
6+
"id": "1a559689",
77
"metadata": {
88
"deletable": false,
99
"editable": false
@@ -115,6 +115,24 @@
115115
"plt.show()"
116116
]
117117
},
118+
{
119+
"cell_type": "markdown",
120+
"id": "69404554",
121+
"metadata": {
122+
"tags": [
123+
"otter_answer_cell"
124+
]
125+
},
126+
"source": [
127+
"## Part 1, continued\n",
128+
"\n",
129+
"Now that we have this line, we need to make it work as input to our state space system. While the real world is continuous, computers are discrete. Computers evaluate the system at specific time points, with specific-sized time steps. If the time steps are too small, the simulation will be more accurate (capturing all of the contours of the road), but will take a very long time to complete. If the time steps are too big, the simulation will be fast, but inaccurate -- it might miss an important road feature.\n",
130+
"\n",
131+
"We can explore this phenomenon by evaluating our bump with different sized time steps. We will use Numpy's `np.interp` function to interpolate the line at specific time points.\n",
132+
"\n",
133+
"Let's first interpolate the line every 10ms."
134+
]
135+
},
118136
{
119137
"cell_type": "code",
120138
"execution_count": null,
@@ -157,15 +175,17 @@
157175
},
158176
{
159177
"cell_type": "markdown",
160-
"id": "a4ff0a87",
161-
"metadata": {},
178+
"id": "28a12705",
179+
"metadata": {
180+
"tags": [
181+
"otter_answer_cell"
182+
]
183+
},
162184
"source": [
163-
"## Part 1, cont.\n",
164-
"Now that we have this line, we need to make it work as input to our state space system. While the real world is continuous, computers are discrete. Computers evaluate the system at specific time points, with specific-sized time steps. If the time steps are too small, the simulation will be more accurate (capturing all of the contours of the road), but will take a very long time to complete. If the time steps are too big, the simulation will be fast, but inaccurate -- it might miss an important road feature.\n",
165-
"\n",
166-
"We can explore this phenomenon by evaluating our bump with different sized time steps. We will use Numpy's `np.interp` function to interpolate the line at specific time points.\n",
185+
"## Part 1, cont\n",
186+
"With `dt` set to `10ms`, the interpolated road still looks like our road. But what happens if `dt` is too large?\n",
167187
"\n",
168-
"Let's first interpolate the line every 10ms."
188+
"Let's first define a function to interpolate a line with a given car `velocity` and `dt` so we can experiment easily with different `dt` values."
169189
]
170190
},
171191
{
@@ -211,21 +231,10 @@
211231
"plt.show()"
212232
]
213233
},
214-
{
215-
"cell_type": "markdown",
216-
"id": "fc98cd4c",
217-
"metadata": {},
218-
"source": [
219-
"## Part 1, cont\n",
220-
"With `dt` set to `10ms`, the interpolated road still looks like our road. But what happens if `dt` is too large?\n",
221-
"\n",
222-
"Let's first define a function to interpolate a line with a given car `velocity` and `dt` so we can experiment easily with different `dt` values."
223-
]
224-
},
225234
{
226235
"cell_type": "code",
227236
"execution_count": null,
228-
"id": "e36ca00c",
237+
"id": "aeecb898",
229238
"metadata": {
230239
"deletable": false,
231240
"editable": false
@@ -239,8 +248,9 @@
239248
"cell_type": "markdown",
240249
"id": "17c77e46",
241250
"metadata": {
242-
"deletable": false,
243-
"editable": false
251+
"tags": [
252+
"otter_answer_cell"
253+
]
244254
},
245255
"source": [
246256
"Now, use `interpolate_road` to find a `dt` where the bump in the road disappears. Graph your results."
@@ -279,7 +289,7 @@
279289
{
280290
"cell_type": "code",
281291
"execution_count": null,
282-
"id": "abcd309d",
292+
"id": "62e43826",
283293
"metadata": {
284294
"deletable": false,
285295
"editable": false
@@ -293,8 +303,9 @@
293303
"cell_type": "markdown",
294304
"id": "45df6b1f",
295305
"metadata": {
296-
"deletable": false,
297-
"editable": false
306+
"tags": [
307+
"otter_answer_cell"
308+
]
298309
},
299310
"source": [
300311
"## Part 2: The state space model for a quarter car\n",
@@ -308,8 +319,9 @@
308319
"cell_type": "markdown",
309320
"id": "73e41a58",
310321
"metadata": {
311-
"deletable": false,
312-
"editable": false
322+
"tags": [
323+
"otter_answer_cell"
324+
]
313325
},
314326
"source": [
315327
"\n",
@@ -485,8 +497,9 @@
485497
"cell_type": "markdown",
486498
"id": "ebff6274",
487499
"metadata": {
488-
"deletable": false,
489-
"editable": false
500+
"tags": [
501+
"otter_answer_cell"
502+
]
490503
},
491504
"source": [
492505
"### Translating the state space model into Python\n",
@@ -674,7 +687,7 @@
674687
{
675688
"cell_type": "code",
676689
"execution_count": null,
677-
"id": "88f06b9d",
690+
"id": "45c400e3",
678691
"metadata": {
679692
"deletable": false,
680693
"editable": false
@@ -700,18 +713,6 @@
700713
"First, let's generalize the animation function so that you can easily animate new cars."
701714
]
702715
},
703-
{
704-
"cell_type": "markdown",
705-
"id": "47098ab4",
706-
"metadata": {
707-
"tags": [
708-
"otter_answer_cell"
709-
]
710-
},
711-
"source": [
712-
"_Type your answer here, replacing this text._"
713-
]
714-
},
715716
{
716717
"cell_type": "code",
717718
"execution_count": null,
@@ -771,7 +772,12 @@
771772
},
772773
"outputs": [],
773774
"source": [
774-
"# GUIDE: Animate car with the large timestamp that misses the bump."
775+
"# Next, let's try simulating the same quarter car on the same road, \n",
776+
"# but with the large `dt` value that you used previously. \n",
777+
"# You will notice that the car does not react to the bump because the simulation did not \"see\" the bump!\n",
778+
"# \n",
779+
"# GUIDE: Animate car with the large timestamp that misses the bump.\n",
780+
"..."
775781
]
776782
},
777783
{
@@ -785,7 +791,11 @@
785791
},
786792
"outputs": [],
787793
"source": [
788-
"# GUIDE: animate car with a small timestamp."
794+
"# Now, let's try the same simulation, but make `dt` very small. \n",
795+
"# What ends up happening? Does your animation complete?\n",
796+
"# \n",
797+
"# GUIDE: animate car with a small timestamp.\n",
798+
"..."
789799
]
790800
},
791801
{
@@ -909,7 +919,7 @@
909919
{
910920
"cell_type": "code",
911921
"execution_count": null,
912-
"id": "d9812252",
922+
"id": "96dec755",
913923
"metadata": {
914924
"deletable": false,
915925
"editable": false

0 commit comments

Comments
 (0)