Skip to content

Commit f032e2f

Browse files
committed
Fixed a few minor typos.
1 parent 814e884 commit f032e2f

File tree

5 files changed

+98
-45
lines changed

5 files changed

+98
-45
lines changed

assignments/Homework-2.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,12 @@
521521
"\\end{align} \n",
522522
"\n",
523523
"\n",
524-
"where $x_i$ is the fraction of funds invested in stock $i$ and $x = [x_1, x_2, ..., x_N]^T$. The objective is to minimize the variance of the return rate. (As practice for the next exam, try deriving this from the error propagation formulas.) This requires the expected return rate to be at least $\\rho$. Finally, the allocation of funds must sum to 100%.\n",
524+
"where $x_i$ is the fraction of funds invested in stock $i$ and $x = [x_1, x_2, ..., x_N]^T$. The objective is to minimize the variance of the return rate. (As practice for the next exam, try deriving this from the error propagation formulas). This requires the expected return rate to be at least $\\rho$. Finally, the allocation of funds must sum to 100%.\n",
525525
"\n",
526526
"Write Python code to solve for $\\rho = 0.08\\%.$ Report both the optimal allocation of funds and the standard deviation of the return rate. \n",
527527
"*Hint*:\n",
528528
"1. Be mindful of units.\n",
529-
"2. You can solve with problem using the Pyomo function given below\n",
529+
"2. You can solve the problem using the Pyomo function given below\n",
530530
"3. $:=$ means ''defined as''\n",
531531
"\n",
532532
"Store your answer in `std_dev`."
@@ -693,9 +693,9 @@
693693
]
694694
},
695695
"kernelspec": {
696-
"display_name": "Python 3 (ipykernel)",
696+
"display_name": "Python [conda env:controls] *",
697697
"language": "python",
698-
"name": "python3"
698+
"name": "conda-env-controls-py"
699699
},
700700
"language_info": {
701701
"codemirror_mode": {
@@ -707,7 +707,7 @@
707707
"name": "python",
708708
"nbconvert_exporter": "python",
709709
"pygments_lexer": "ipython3",
710-
"version": "3.10.12"
710+
"version": "3.10.16"
711711
}
712712
},
713713
"nbformat": 4,

assignments/Lab-5-Open-Loop-Optimization.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"# To complete the experiment, change this to True\n",
8686
"# After completing the experiment, be sure to change it back to False\n",
8787
"# This will prevent you from overwriting your data\n",
88-
"run_tamb_tclab = False\n",
88+
"run_tamb_tclab = True\n",
8989
"\n",
9090
"from tclab import TCLab, clock, Historian, Plotter, setup\n",
9191
"import numpy as np\n",
@@ -140,7 +140,7 @@
140140
"\n",
141141
"The code block below provides a library for performing several analysis tasks with our model. This is a `class`, which is a more sophisticated way to modularize our code. Briefly, classes store both data and methods to manipulate the data.\n",
142142
"\n",
143-
"Take a few minutes to study this code. Note the missing lines of code to fill in when you get to Exercise 1. A few features:\n",
143+
"Take a few minutes to study this code. Note the missing lines of code to fill in when you get to Exercise 2. (Adding these constraints will not impact your Exercise 1 answer.) A few features:\n",
144144
"* It supports four modes:\n",
145145
" * `simulate`: solve the model with all of the inputs specified (zero degrees of freedom)\n",
146146
" * `optimize`: determine the best $u(t)$ to track the desired $T_{set}(t)$\n",
@@ -195,7 +195,7 @@
195195
"\n",
196196
" def __init__(self, mode, t_data, u_data, d_data, Tset_data, \n",
197197
" TS_data, Tamb = Tamb, alpha = 0.00016, P1 = 100,\n",
198-
" Ua = 0.0261, Ub = 0.0222, CpH = 1.335, CpS = 1.328,\n",
198+
" Ua = 0.050, Ub = 0.097, CpH = 2.274, CpS = 5.046,\n",
199199
" integrate_to_initialize=True, obj_weight_observe=0.1,\n",
200200
" obj_weight_optimize=0.01\n",
201201
" ):\n",
@@ -735,7 +735,7 @@
735735
"# To complete the experiment, change this to True\n",
736736
"# After completing the experiment, be sure to change it back to False\n",
737737
"# This will prevent you from overwriting your data\n",
738-
"run_exercise2_tclab = False\n",
738+
"run_exercise2_tclab = True\n",
739739
"\n",
740740
"if run_exercise2_tclab:\n",
741741
"\n",
@@ -828,8 +828,8 @@
828828
"\n",
829829
"if run_exercise2_tclab:\n",
830830
" data_file = save_tclab_data(h,\n",
831-
" excercise2_tclab_data_file, # tip: change this to end in \"2\" when copying code later in assignment\n",
832-
" False\n",
831+
" excercise2_tclab_data_file, # tip: change this to end in \"2\" when copying code later in assignment\n",
832+
" True\n",
833833
" )"
834834
]
835835
},
@@ -1200,7 +1200,7 @@
12001200
"# To complete the experiment, change this to True\n",
12011201
"# After completing the experiment, be sure to change it back to False\n",
12021202
"# This will prevent you from overwriting your data\n",
1203-
"run_exercise6_tclab = False\n",
1203+
"run_exercise6_tclab = True\n",
12041204
"\n",
12051205
"from tclab import TCLab, clock, Historian, Plotter, setup\n",
12061206
"\n",
@@ -1424,7 +1424,7 @@
14241424
"name": "python",
14251425
"nbconvert_exporter": "python",
14261426
"pygments_lexer": "ipython3",
1427-
"version": "3.10.15"
1427+
"version": "3.10.16"
14281428
}
14291429
},
14301430
"nbformat": 4,

assignments/Lab-6-MPC.ipynb

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@
4141
"Before beginning this lab, connect your TCLab device and run the following cell to estimate your ambient temperature.\n"
4242
]
4343
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"id": "1144c3ef",
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"# Set default parameters for publication quality plots\n",
52+
"import matplotlib.pyplot as plt\n",
53+
"\n",
54+
"SMALL_SIZE = 14\n",
55+
"MEDIUM_SIZE = 16\n",
56+
"BIGGER_SIZE = 18\n",
57+
"\n",
58+
"plt.rc(\"font\", size=SMALL_SIZE) # controls default text sizes\n",
59+
"plt.rc(\"axes\", titlesize=SMALL_SIZE) # fontsize of the axes title\n",
60+
"plt.rc(\"axes\", labelsize=MEDIUM_SIZE) # fontsize of the x and y labels\n",
61+
"plt.rc(\"xtick\", labelsize=SMALL_SIZE) # fontsize of the tick labels\n",
62+
"plt.rc(\"ytick\", labelsize=SMALL_SIZE) # fontsize of the tick labels\n",
63+
"plt.rc(\"legend\", fontsize=SMALL_SIZE) # legend fontsize\n",
64+
"plt.rc(\"figure\", titlesize=BIGGER_SIZE) "
65+
]
66+
},
4467
{
4568
"cell_type": "code",
4669
"execution_count": null,
@@ -143,7 +166,6 @@
143166
"metadata": {},
144167
"outputs": [],
145168
"source": [
146-
"import matplotlib.pyplot as plt\n",
147169
"from scipy import interpolate\n",
148170
"import numpy as np\n",
149171
"\n",
@@ -1006,6 +1028,41 @@
10061028
"plt.show()"
10071029
]
10081030
},
1031+
{
1032+
"cell_type": "code",
1033+
"execution_count": null,
1034+
"id": "32106afa",
1035+
"metadata": {},
1036+
"outputs": [],
1037+
"source": [
1038+
"import os.path\n",
1039+
"\n",
1040+
"def save_tclab_data(h, file_name, overwrite_file=False):\n",
1041+
" '''\n",
1042+
" Save TCLab data to csv file\n",
1043+
" Arguments:\n",
1044+
" h: tclab historian objective\n",
1045+
" file_name: valid file name as a string\n",
1046+
" overwrite_file: bool, if True, overwrite exisiting file\n",
1047+
" default is False to safeguard against accidentally rerunning this function\n",
1048+
" '''\n",
1049+
"\n",
1050+
" if not overwrite_file and os.path.isfile('./'+file_name):\n",
1051+
" raise FileExistsError(file_name + ' already exisits. Either choose a new filename or set overwrite_file = True.')\n",
1052+
" else:\n",
1053+
" h.to_csv(file_name)\n",
1054+
" print(\"Successfully saved data to \"+file_name)\n",
1055+
"\n",
1056+
" return file_name\n",
1057+
"\n",
1058+
"excercise3_tclab_data_file = 'tclab-mpc1.csv'\n",
1059+
"\n",
1060+
"data_file = save_tclab_data(h,\n",
1061+
" excercise3_tclab_data_file, \n",
1062+
" True\n",
1063+
")"
1064+
]
1065+
},
10091066
{
10101067
"cell_type": "markdown",
10111068
"id": "e6eb15cd",
@@ -1191,7 +1248,7 @@
11911248
],
11921249
"metadata": {
11931250
"kernelspec": {
1194-
"display_name": "Python 3 (ipykernel)",
1251+
"display_name": "controls",
11951252
"language": "python",
11961253
"name": "python3"
11971254
},
@@ -1205,7 +1262,7 @@
12051262
"name": "python",
12061263
"nbconvert_exporter": "python",
12071264
"pygments_lexer": "ipython3",
1208-
"version": "3.9.12"
1265+
"version": "3.10.16"
12091266
}
12101267
},
12111268
"nbformat": 4,

notebooks/2/First-Order-Model-for-a-Single-Heater.ipynb

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@
8484
"\n",
8585
"where\n",
8686
"\n",
87-
"$$\\begin{align*}\n",
87+
"\\begin{align*}\n",
8888
"0 & \\leq u_1 \\leq 100 \\\\\n",
8989
"0 & \\leq P_1 \\leq 255 \n",
90-
"\\end{align*}$$\n",
90+
"\\end{align*}\n",
9191
"\n",
9292
"A parameter $\\alpha$ is needed to model the experimentally observed power delivered to the heaters in units of watts.\n",
9393
"\n",
@@ -170,11 +170,9 @@
170170
"\n",
171171
"Putting these terms together in the energy balance yields a first-order model for the response of the heater/sensor assembly on the Temperature Control Laboratory.\n",
172172
"\n",
173-
"$$\n",
174173
"\\begin{align}\n",
175174
"C_p\\frac{dT_1}{dt} & = U_a(T_{amb} - T_1) + \\alpha P_1u_1 \\\\\n",
176-
"\\end{align}\n",
177-
"$$\n"
175+
"\\end{align}"
178176
]
179177
},
180178
{
@@ -286,9 +284,9 @@
286284
"\n",
287285
"We'll begin our analysis by investigating the steady-state response of this system to a steady-state input $\\bar{u}_{1}$. At steady-state all variables are constant so $\\frac{dT_1}{dt} = 0$, which leaves \n",
288286
"\n",
289-
"$$\\begin{align}\n",
287+
"\\begin{align}\n",
290288
"0 = U_a(T_{amb} - \\bar{T}_1) + \\alpha P_1\\bar{u}_{1}\n",
291-
"\\end{align}$$\n",
289+
"\\end{align}\n",
292290
"\n",
293291
"Solving for $\\bar{T}_{1}$\n",
294292
"\n",
@@ -325,41 +323,41 @@
325323
"\n",
326324
"In examining the response of the temperature control laboratory, we see the temperature is a deviation from ambient temperature, i.e.,\n",
327325
"\n",
328-
"$$\\begin{align}\n",
326+
"\\begin{align}\n",
329327
"T_1' = T_1 - T_{amb}\n",
330-
"\\end{align}$$\n",
328+
"\\end{align}\n",
331329
"\n",
332330
"For process control purposes, we are often interested in the deviation of a process variable from a nominal value. In this case the choice of deviation variable is clearly obvious which is designated $T_1'$. From the steady state equation we see\n",
333331
"\n",
334-
"$$\\begin{align}\n",
332+
"\\begin{align}\n",
335333
"\\bar{T}_1' = \\bar{T}_1 - T_{amb} = \\frac{\\alpha P_1}{U_a}\\bar{u}_1\n",
336-
"\\end{align}$$\n",
334+
"\\end{align}\n",
337335
"\n",
338336
"which is a somewhat simpler expression.\n",
339337
"\n",
340338
"Let's see what happens to the transient model. Substituting $T_1 = T_{amb} + T_1'$ into the differential equation gives\n",
341339
"\n",
342-
"$$\\begin{align}\n",
340+
"\\begin{align}\n",
343341
"C_p\\frac{d(T_{amb}+T_1')}{dt} & = U_a(T_{amb} - (T_{amb} + T_1')) + \\alpha P_1u_1\n",
344-
"\\end{align}$$\n",
342+
"\\end{align}\n",
345343
"\n",
346344
"Expanding these terms\n",
347345
"\n",
348-
"$$\\begin{align}\n",
346+
"\\begin{align}\n",
349347
"C_p\\underbrace{\\frac{dT_{amb}}{dt}}_{0} + C_p\\frac{dT_1'}{dt} & = U_a(\\underbrace{T_{amb} - T_{amb}}_{0} - T_1') + \\alpha P_1u_1\n",
350-
"\\end{align}$$\n",
348+
"\\end{align}\n",
351349
"\n",
352350
"we see several terms drop out. The derivative of any constant is zero, and see a cancelation on the right hand side, leaving\n",
353351
"\n",
354-
"$$\\begin{align}\n",
352+
"\\begin{align}\n",
355353
"C_p\\frac{dT_1'}{dt} & = - U_aT_1' + \\alpha P_1u_1\n",
356-
"\\end{align}$$\n",
354+
"\\end{align}\n",
357355
"\n",
358356
"One last manipulation will bring this model into a commonly used standard form\n",
359357
"\n",
360-
"$$\\begin{align}\n",
358+
"\\begin{align}\n",
361359
"\\frac{dT_1'}{dt} & = - \\frac{U_a}{C_p}T_1' + \\frac{\\alpha P_1}{C_p}u_1\n",
362-
"\\end{align}$$"
360+
"\\end{align}"
363361
]
364362
},
365363
{
@@ -381,9 +379,9 @@
381379
"\n",
382380
"A standard form for a single differential equation is\n",
383381
"\n",
384-
"$$\\begin{align}\n",
382+
"\\begin{align}\n",
385383
"\\frac{dx}{dt} & = ax + bu\n",
386-
"\\end{align}$$\n",
384+
"\\end{align}\n",
387385
"\n",
388386
"where $a$ and $b$ are model constants, $x$ is the dependent variable, and $u$ is an exogeneous input. "
389387
]
@@ -436,20 +434,20 @@
436434
"\n",
437435
"We now apply this textbook solution to the model equation. Comparing equations, we make the following identifications\n",
438436
"\n",
439-
"$$\\begin{align}\n",
437+
"\\begin{align}\n",
440438
"T_1' \\sim x \\\\\n",
441439
"-\\frac{U_a}{C_p} \\sim a \\\\\n",
442440
"\\frac{\\alpha P_1}{C_p} \\sim b \\\\\n",
443441
"u_1 \\sim u\n",
444-
"\\end{align}$$\n",
442+
"\\end{align}\n",
445443
"\n",
446444
"Substituting these terms into the standard solution we confirm the steady-state solution found above, and provides a solution for the transient response of the deviation variables.\n",
447445
"\n",
448-
"$$\\begin{align}\n",
446+
"\\begin{align}\n",
449447
"\\bar{x} = -\\frac{b}{a}\\bar{u} \\qquad & \\Rightarrow \\qquad \\bar{T}_{1}' = \\frac{\\alpha P_1}{U_a}\\bar{u}_{1} \\\\\n",
450448
"x(t) = \\bar{x} + \\left[x(t_0) - \\bar{x}\\right] e^{a(t-t_0)} \\qquad & \\Rightarrow \\qquad\n",
451449
"T_1'(t) = \\frac{\\alpha P_1}{U_a}\\bar{u}_{1} + \\left[T_1'(t_0) - \\frac{\\alpha P_1}{U_a}\\bar{u}_{1}\\right]e^{-\\frac{U_a}{C_p}(t-t_0)}\n",
452-
"\\end{align}$$"
450+
"\\end{align}"
453451
]
454452
},
455453
{

notebooks/2/Properties-of-Scalar-First-Order-Linear-Systems.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,10 @@
365365
"\n",
366366
"Normalize the response as\n",
367367
"\n",
368-
"$$\n",
369368
"\\begin{align}\n",
370369
"z(t) & = 1 - \\frac{x(t)}{x(t_0)} \\\\\n",
371370
"& = 1 - e^{a(t-t_0)}\n",
372371
"\\end{align}\n",
373-
"$$\n",
374372
"\n",
375373
"The following table shows the response of a first order system as a fraction of the initial condition.\n",
376374
"\n",
@@ -759,10 +757,10 @@
759757
"\n",
760758
"We found two key parameters that describe the behavior of this systems in terms that can be easily indentified from a plot of the step response, the time constant $\\tau$ and gain $K$.\n",
761759
"\n",
762-
"$$\\begin{align*}\n",
760+
"\\begin{align*}\n",
763761
"\\tau & = -1/a \\\\\n",
764762
"K & = - \\frac{b}{a}\n",
765-
"\\end{align*}$$\n",
763+
"\\end{align*}\n",
766764
"\n",
767765
"Obviously, once $K$ and $\\tau$ are estimated, values for $a$ and $b$ are easily computed. But sometimes it is more transparent simply to write the linear system using $K$ and $\\tau$ directly, as\n",
768766
"\n",

0 commit comments

Comments
 (0)