Skip to content

Commit 557f2c2

Browse files
committed
update CDS 110, L3
1 parent d4c75a3 commit 557f2c2

1 file changed

Lines changed: 18 additions & 36 deletions

File tree

‎examples/cds110-L3_lti-systems.ipynb‎

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
"outputs": [],
152152
"source": [
153153
"response = ct.initial_response(sys, X0=[1, 0, 0, 0])\n",
154-
"out = response.plot()"
154+
"cplt = response.plot()"
155155
]
156156
},
157157
{
@@ -195,19 +195,9 @@
195195
"metadata": {},
196196
"outputs": [],
197197
"source": [
198-
"# Do some Python magic to get different colors\n",
199-
"from itertools import cycle\n",
200-
"prop_cycle = plt.rcParams['axes.prop_cycle']\n",
201-
"colors = cycle(prop_cycle.by_key()['color'])\n",
202-
"\n",
203198
"for X0 in [[1, 0, 0, 0], [0, 2, 0, 0], [1, 2, 0, 0], [0, 0, 1, 0], [0, 0, 2, 0]]:\n",
204199
" response = ct.initial_response(sys, T=20, X0=X0)\n",
205-
" try:\n",
206-
" response.plot(color=next(colors), label=f\"{X0=}\")\n",
207-
" except TypeError:\n",
208-
" # Earlier versions of python-control don't allow relabeling\n",
209-
" response.sysname = f\"{X0=}\"\n",
210-
" response.plot(color=next(colors))"
200+
" response.plot(label=f\"{X0=}\")"
211201
]
212202
},
213203
{
@@ -227,7 +217,7 @@
227217
"metadata": {},
228218
"outputs": [],
229219
"source": [
230-
"out = ct.step_response(sys).plot()"
220+
"cplt = ct.step_response(sys).plot()"
231221
]
232222
},
233223
{
@@ -267,7 +257,7 @@
267257
"outputs": [],
268258
"source": [
269259
"stepresp = ct.step_response(sys)\n",
270-
"out = stepresp.plot(plot_inputs=True)"
260+
"cplt = stepresp.plot(plot_inputs=True)"
271261
]
272262
},
273263
{
@@ -277,7 +267,7 @@
277267
"outputs": [],
278268
"source": [
279269
"# Plot the inputs on top of the outputs\n",
280-
"out = stepresp.plot(plot_inputs='overlay')"
270+
"cplt = stepresp.plot(plot_inputs='overlay')"
281271
]
282272
},
283273
{
@@ -331,11 +321,10 @@
331321
"outputs": [],
332322
"source": [
333323
"# Show that the system response is linear\n",
334-
"out = resp3.plot()\n",
335-
"axs = ct.get_plot_axes(out)\n",
336-
"axs[0, 0].plot(resp1.time, resp1.outputs[0] + resp2.outputs[0], 'k--')\n",
337-
"axs[1, 0].plot(resp1.time, resp1.outputs[1] + resp2.outputs[1], 'k--')\n",
338-
"axs[2, 0].plot(resp1.time, resp1.inputs[0] + resp2.inputs[0], 'k--');"
324+
"cplt = resp3.plot()\n",
325+
"cplt.axes[0, 0].plot(resp1.time, resp1.outputs[0] + resp2.outputs[0], 'k--')\n",
326+
"cplt.axes[1, 0].plot(resp1.time, resp1.outputs[1] + resp2.outputs[1], 'k--')\n",
327+
"cplt.axes[2, 0].plot(resp1.time, resp1.inputs[0] + resp2.inputs[0], 'k--');"
339328
]
340329
},
341330
{
@@ -350,11 +339,10 @@
350339
"resp2 = ct.forced_response(sys, T, U2, X0=X0)\n",
351340
"resp3 = ct.forced_response(sys, T, U1 + U2, X0=X0)\n",
352341
"\n",
353-
"out = resp3.plot()\n",
354-
"axs = ct.get_plot_axes(out)\n",
355-
"axs[0, 0].plot(resp1.time, resp1.outputs[0] + resp2.outputs[0], 'k--')\n",
356-
"axs[1, 0].plot(resp1.time, resp1.outputs[1] + resp2.outputs[1], 'k--')\n",
357-
"axs[2, 0].plot(resp1.time, resp1.inputs[0] + resp2.inputs[0], 'k--');"
342+
"cplt = resp3.plot()\n",
343+
"cplt.axes[0, 0].plot(resp1.time, resp1.outputs[0] + resp2.outputs[0], 'k--')\n",
344+
"cplt.axes[1, 0].plot(resp1.time, resp1.outputs[1] + resp2.outputs[1], 'k--')\n",
345+
"cplt.axes[2, 0].plot(resp1.time, resp1.inputs[0] + resp2.inputs[0], 'k--');"
358346
]
359347
},
360348
{
@@ -375,16 +363,10 @@
375363
"# Manual computation of the frequency response\n",
376364
"resp = ct.input_output_response(sys, T, np.sin(1.35 * T))\n",
377365
"\n",
378-
"try:\n",
379-
" out = resp.plot(\n",
366+
"cplt = resp.plot(\n",
380367
" plot_inputs='overlay', \n",
381368
" legend_map=np.array([['lower left'], ['lower left']]),\n",
382-
" label=[['q1', 'u[0]'], ['q2', None]])\n",
383-
"except TypeError:\n",
384-
" # Earlier versions of python-control don't allow relabeling\n",
385-
" out = resp.plot(\n",
386-
" plot_inputs='overlay',\n",
387-
" legend_map=np.array([['lower left'], ['lower left']]))"
369+
" label=[['q1', 'u[0]'], ['q2', None]])"
388370
]
389371
},
390372
{
@@ -457,7 +439,7 @@
457439
"outputs": [],
458440
"source": [
459441
"freqresp = ct.frequency_response(sys)\n",
460-
"out = freqresp.plot()"
442+
"cplt = freqresp.plot()"
461443
]
462444
},
463445
{
@@ -477,7 +459,7 @@
477459
"metadata": {},
478460
"outputs": [],
479461
"source": [
480-
"out = ct.bode_plot(sys, overlay_outputs=True)"
462+
"cplt = ct.bode_plot(sys, overlay_outputs=True)"
481463
]
482464
},
483465
{
@@ -497,7 +479,7 @@
497479
"metadata": {},
498480
"outputs": [],
499481
"source": [
500-
"out = ct.frequency_response(\n",
482+
"cplt = ct.frequency_response(\n",
501483
" coupled.linearize([0, 0, 0, 0], [0], params={'c': 0.01})\n",
502484
").plot(overlay_outputs=True)"
503485
]

0 commit comments

Comments
 (0)