Skip to content

Commit d592789

Browse files
authored
updates to notebooks1 (#20)
* update hyperlinks to solutions * update reference for links to/from answer section * updates to notebooks1
1 parent 3d6fbe5 commit d592789

File tree

38 files changed

+418
-413
lines changed

38 files changed

+418
-413
lines changed

notebook1-4_test/notebook1-4_test.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"cell_type": "markdown",
2424
"metadata": {},
2525
"source": [
26-
"### <a name=\"ex1\"></a>Exercise 1\n",
26+
"### <a id=\"ex1\"></a>Exercise 1\n",
2727
"\n",
2828
"Write a function that plots a square centered at the origin. The length of the side of the square is $L$. The input of the function is the length $L$. \n",
2929
"\n",
@@ -60,7 +60,7 @@
6060
"cell_type": "markdown",
6161
"metadata": {},
6262
"source": [
63-
"### <a name=\"ex2\"></a>Exercise 2\n",
63+
"### <a id=\"ex2\"></a>Exercise 2\n",
6464
"Write a function called `countsquares` that takes as input the filename of a file that consists of a bunch of numbers separated by spaces. Inside the function, you must first read the numbers from the filename and then you must determine how many of these numbers are a perfect square. A perfect square means that the root of the number is an integer (i.e., 1, 4, 16, 25, etc.). The function returns the number of perfect squares in the file. Note: to convert a number to an integer, use the `int` function. \n",
6565
"\n",
6666
"Demonstrate that your function works by using the file `numbers2016.txt` and execute the following line of code:\n",
@@ -86,7 +86,7 @@
8686
"cell_type": "markdown",
8787
"metadata": {},
8888
"source": [
89-
"### <a name=\"ex3\"></a>Exercise 3\n",
89+
"### <a id=\"ex3\"></a>Exercise 3\n",
9090
"The file `quiz_answers.dat` contains the result of a small multiple-choice quiz with 8 questions. Every row contains the 8 answers to the quiz of one of the students. Your job is to count how many students had the correct answer for each question. Write a double loop to compute the number of correct answers for each question and present the results in a bar graph. The correct answers for the 8 questions of the quiz are: `a b c d a b c d`"
9191
]
9292
},
@@ -134,7 +134,7 @@
134134
"cell_type": "markdown",
135135
"metadata": {},
136136
"source": [
137-
"### <a name=\"ex5\"></a>Exercise 5\n",
137+
"### <a id=\"ex5\"></a>Exercise 5\n",
138138
"Write a function that computes the percentage of grades that is above a given value. The function takes as input arguments an array with grades between 1 and 10 and a minimum value and returns the precentage of grades (so between 0% and 100%) that are above or equal to that value. Demonstrate that your function works by loading the grades in the file `schoolgrades2016.txt` and print the result of the function to the screen with two decimal places, given a minimum value of 7."
139139
]
140140
},
@@ -163,31 +163,31 @@
163163
"cell_type": "markdown",
164164
"metadata": {},
165165
"source": [
166-
"<a name=\"ex1answer\">Answer to Exercise 1</a>\n",
166+
"<a id=\"ex1answer\">Answer to Exercise 1</a>\n",
167167
"\n",
168168
"You probably know what this should look like\n",
169169
"\n",
170170
"<a href=\"#ex1\">Back to Exercise 1</a>\n",
171171
"\n",
172-
"<a name=\"ex2answer\">Answer to Exercise 2</a>\n",
172+
"<a id=\"ex2answer\">Answer to Exercise 2</a>\n",
173173
"\n",
174174
"93\n",
175175
"\n",
176176
"<a href=\"#ex2\">Back to Exercise 2</a>\n",
177177
"\n",
178-
"<a name=\"ex3answer\">Answer to Exercise 3</a>\n",
178+
"<a id=\"ex3answer\">Answer to Exercise 3</a>\n",
179179
"\n",
180180
"Q1: 4, Q2: 4, Q3: 5, Q4:3, Q5:5, Q6:5, Q7:4, Q8:4\n",
181181
"\n",
182182
"<a href=\"#ex3\">Back to Exercise 3</a>\n",
183183
"\n",
184-
"<a name=\"ex4answer\">Answer to Exercise 4</a>\n",
184+
"<a id=\"ex4answer\">Answer to Exercise 4</a>\n",
185185
"\n",
186186
"Your graph should look like the provided figure\n",
187187
"\n",
188188
"<a href=\"#ex4\">Back to Exercise 4</a>\n",
189189
"\n",
190-
"<a name=\"ex5answer\">Answer to Exercise 5</a>\n",
190+
"<a id=\"ex5answer\">Answer to Exercise 5</a>\n",
191191
"\n",
192192
"31.3\n",
193193
"\n",

notebook10_continuous_random_variables/py_exploratory_comp_10.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"cell_type": "markdown",
122122
"metadata": {},
123123
"source": [
124-
"### Exercise 1: <a name=\"back1\"></a>First histogram\n",
124+
"### Exercise 1: <a id=\"back1\"></a>First histogram\n",
125125
"Generate 1000 random numbers from a Normal distribution with mean 100 and standard deviation 10. Compute and print to the screen the mean and standard deviation of your data. Create two graphs above each other using the `plt.subplot` command. In the top graph, plot a histogram using 20 bins going from 50 to 150. Note that with this size of a data set (1000 data points), the histogram starts to look a lot more like the typical bell-shaped curve of a Normal distribution. Add a red line representing the probability density function of the underlying normal distribution to the graph. In the bottom graph, draw a histogram of the cumulative distribution function, by setting the keyword `cumulative=True` (see `plt.hist?` for details). For the latter graph, use the keyword `align='right'` so that the bars are centered on the right bin edges (so that the line you are drawing next will approximately go through the centers of the bars). Add a red line representing the cumulative distribution function of the underlying normal distribution to the graph using the `norm.cdf` function, which works the same as the `norm.pdf` function but computes the cumulative distribution function (cdf). Finally, make sure the limits along the horizontal axis are the same for both graphs. "
126126
]
127127
},
@@ -181,7 +181,7 @@
181181
"cell_type": "markdown",
182182
"metadata": {},
183183
"source": [
184-
"### Expercise 2. <a name=\"back2\"></a>Lower and upper quartile\n",
184+
"### Expercise 2. <a id=\"back2\"></a>Lower and upper quartile\n",
185185
"Generate 100 data points from a normal distribution with a mean of 20 and a standard deviation of 4. Compute the interquartile range (25%-75% range). Compute the theoretical value of the interquartile range and compare it to the interquartile range of the data. Draw a histogram of the cumulative distribution. Add red vertical lines to your graph for the 0.25 and 0.75 empirical quantiles of the data, and black vertical lines for the 0.25 and 0.75 quantiles of the underlying distribution. Vertical lines that span the graph may be added with the `plt.axvline` function, which takes the $x$ value of the line as an argument. To specify the color of the vertical line, use the `color` keyword argument."
186186
]
187187
},
@@ -391,7 +391,7 @@
391391
"cell_type": "markdown",
392392
"metadata": {},
393393
"source": [
394-
"### Exercise 3. <a name=\"back3\"></a>Loading experimental data and basic operations\n",
394+
"### Exercise 3. <a id=\"back3\"></a>Loading experimental data and basic operations\n",
395395
"Load the data in the file `douglas_data.csv` using the `read_csv` command of the `pandas` package (see the `pandas` Notebook if you forgot how). Use the `skiprows` and `skipinitialspace` keywords. Carry out the following three tasks:\n",
396396
"\n",
397397
"* Determine and report the minimum and maximum measured values of the bending strength. \n",
@@ -417,7 +417,7 @@
417417
"cell_type": "markdown",
418418
"metadata": {},
419419
"source": [
420-
"### Exercise 4. <a name=\"back4\"></a>Boxplot of moisture content\n",
420+
"### Exercise 4. <a id=\"back4\"></a>Boxplot of moisture content\n",
421421
"The moisture content is defined as the mass of moisture in a beam divided by the total mass of the beam (including the moisture) and is recorded as a percentage. Compute and report the mean and standard deviation of the moisture content, and make a box plot."
422422
]
423423
},
@@ -453,7 +453,7 @@
453453
"cell_type": "markdown",
454454
"metadata": {},
455455
"source": [
456-
"### Exercise 5. <a name=\"back5\"></a>Histogram of bending strength\n",
456+
"### Exercise 5. <a id=\"back5\"></a>Histogram of bending strength\n",
457457
"Create a histogram of the bending strength. Add labels to the axes. Does the histogram look like a Normal distribution? On the same graph draw a red vertical line for the experimentally determined 5% bending strength. Print the 0.05 experimental quantile bending strength to the screen."
458458
]
459459
},
@@ -475,7 +475,7 @@
475475
"cell_type": "markdown",
476476
"metadata": {},
477477
"source": [
478-
"### Exercise 6. <a name=\"back6\"></a>Normal distribution for bending strength\n",
478+
"### Exercise 6. <a id=\"back6\"></a>Normal distribution for bending strength\n",
479479
"Let's try to fit a normal distribution to the bending strength data. This is obviously not quite correct, as the tail of the Normal distribution will extend below zero to the left, which is unrealistic. If the part of the tail below zero is small, it may be a reasonable first step. Create a normalized histogram of the bending strength. Compute the mean and standard deviation of the bending strength data and plot on the same graph the Normal probability density function using these estimates of the mean and standard deviation. Add a red vertical line for the 5% bending strength according to the data, and a black vertical line for the 5% bending strength according to the fitted Normal distribution"
480480
]
481481
},
@@ -504,7 +504,7 @@
504504
"cell_type": "markdown",
505505
"metadata": {},
506506
"source": [
507-
"<a name=\"ex1answer\">Answers to Exercise 1</a>"
507+
"<a id=\"ex1answer\">Answers to Exercise 1</a>"
508508
]
509509
},
510510
{
@@ -542,7 +542,7 @@
542542
"source": [
543543
"<a href=\"#back1\">Back to Exercise 1</a>\n",
544544
"\n",
545-
"<a name=\"ex2answer\">Answers to Exercise 2</a>"
545+
"<a id=\"ex2answer\">Answers to Exercise 2</a>"
546546
]
547547
},
548548
{
@@ -573,7 +573,7 @@
573573
"source": [
574574
"<a href=\"#back2\">Back to Exercise 2</a>\n",
575575
"\n",
576-
"<a name=\"ex3answer\">Answers to Exercise 3</a>"
576+
"<a id=\"ex3answer\">Answers to Exercise 3</a>"
577577
]
578578
},
579579
{
@@ -596,7 +596,7 @@
596596
"source": [
597597
"<a href=\"#back3\">Back to Exercise 3</a>\n",
598598
"\n",
599-
"<a name=\"ex4answer\">Answers to Exercise 4</a>"
599+
"<a id=\"ex4answer\">Answers to Exercise 4</a>"
600600
]
601601
},
602602
{
@@ -626,7 +626,7 @@
626626
"source": [
627627
"<a href=\"#back4\">Back to Exercise 4</a>\n",
628628
"\n",
629-
"<a name=\"ex5answer\">Answers to Exercise 5</a>"
629+
"<a id=\"ex5answer\">Answers to Exercise 5</a>"
630630
]
631631
},
632632
{
@@ -648,7 +648,7 @@
648648
"source": [
649649
"<a href=\"#back5\">Back to Exercise 5</a>\n",
650650
"\n",
651-
"<a name=\"ex6answer\">Answers to Exercise 6</a>"
651+
"<a id=\"ex6answer\">Answers to Exercise 6</a>"
652652
]
653653
},
654654
{

notebook10_continuous_random_variables/py_exploratory_comp_10_sol.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
"cell_type": "markdown",
181181
"metadata": {},
182182
"source": [
183-
"### Exercise 1: <a name=\"back1\"></a>First histogram\n",
183+
"### Exercise 1: <a id=\"back1\"></a>First histogram\n",
184184
"Generate 1000 random numbers from a Normal distribution with mean 100 and standard deviation 10. Compute and print to the screen the mean and standard deviation of your data. Create two graphs above each other using the `plt.subplot` command. In the top graph, plot a histogram using 20 bins going from 50 to 150. Note that with this size of a data set (1000 data points), the histogram starts to look a lot more like the typical bell-shaped curve of a Normal distribution. Add a red line representing the probability density function of the underlying normal distribution to the graph. In the bottom graph, draw a histogram of the cumulative distribution function, by setting the keyword `cumulative=True` (see `plt.hist?` for details). For the latter graph, use the keyword `align='right'` so that the bars are centered on the right bin edges (so that the line you are drawing next will approximately go through the centers of the bars). Add a red line representing the cumulative distribution function of the underlying normal distribution to the graph using the `norm.cdf` function, which works the same as the `norm.pdf` function but computes the cumulative distribution function (cdf). Finally, make sure the limits along the horizontal axis are the same for both graphs. "
185185
]
186186
},
@@ -262,7 +262,7 @@
262262
"cell_type": "markdown",
263263
"metadata": {},
264264
"source": [
265-
"### Expercise 2. <a name=\"back2\"></a>Lower and upper quartile\n",
265+
"### Expercise 2. <a id=\"back2\"></a>Lower and upper quartile\n",
266266
"Generate 100 data points from a normal distribution with a mean of 20 and a standard deviation of 4. Compute the interquartile range (25%-75% range). Compute the theoretical value of the interquartile range and compare it to the interquartile range of the data. Draw a histogram of the cumulative distribution. Add red vertical lines to your graph for the 0.25 and 0.75 empirical quantiles of the data, and black vertical lines for the 0.25 and 0.75 quantiles of the underlying distribution. Vertical lines that span the graph may be added with the `plt.axvline` function, which takes the $x$ value of the line as an argument. To specify the color of the vertical line, use the `color` keyword argument."
267267
]
268268
},
@@ -639,7 +639,7 @@
639639
"cell_type": "markdown",
640640
"metadata": {},
641641
"source": [
642-
"### Exercise 3. <a name=\"back3\"></a>Loading experimental data and basic operations\n",
642+
"### Exercise 3. <a id=\"back3\"></a>Loading experimental data and basic operations\n",
643643
"Load the data in the file `douglas_data.csv` using the `read_csv` command of the `pandas` package (see the `pandas` Notebook if you forgot how). Use the `skiprows` and `skipinitialspace` keywords. Carry out the following three tasks:\n",
644644
"\n",
645645
"* Determine and report the minimum and maximum measured values of the bending strength. \n",
@@ -665,7 +665,7 @@
665665
"cell_type": "markdown",
666666
"metadata": {},
667667
"source": [
668-
"### Exercise 4. <a name=\"back4\"></a>Boxplot of moisture content\n",
668+
"### Exercise 4. <a id=\"back4\"></a>Boxplot of moisture content\n",
669669
"The moisture content is defined as the mass of moisture in a beam divided by the total mass of the beam (including the moisture) and is recorded as a percentage. Compute and report the mean and standard deviation of the moisture content, and make a box plot."
670670
]
671671
},
@@ -701,7 +701,7 @@
701701
"cell_type": "markdown",
702702
"metadata": {},
703703
"source": [
704-
"### Exercise 5. <a name=\"back5\"></a>Histogram of bending strength\n",
704+
"### Exercise 5. <a id=\"back5\"></a>Histogram of bending strength\n",
705705
"Create a histogram of the bending strength. Add labels to the axes. Does the histogram look like a Normal distribution? On the same graph draw a red vertical line for the experimentally determined 5% bending strength. Print the 0.05 experimental quantile bending strength to the screen."
706706
]
707707
},
@@ -723,7 +723,7 @@
723723
"cell_type": "markdown",
724724
"metadata": {},
725725
"source": [
726-
"### Exercise 6. <a name=\"back6\"></a>Normal distribution for bending strength\n",
726+
"### Exercise 6. <a id=\"back6\"></a>Normal distribution for bending strength\n",
727727
"Let's try to fit a normal distribution to the bending strength data. This is obviously not quite correct, as the tail of the Normal distribution will extend below zero to the left, which is unrealistic. If the part of the tail below zero is small, it may be a reasonable first step. Create a normalized histogram of the bending strength. Compute the mean and standard deviation of the bending strength data and plot on the same graph the Normal probability density function using these estimates of the mean and standard deviation. Add a red vertical line for the 5% bending strength according to the data, and a black vertical line for the 5% bending strength according to the fitted Normal distribution"
728728
]
729729
},
@@ -752,7 +752,7 @@
752752
"cell_type": "markdown",
753753
"metadata": {},
754754
"source": [
755-
"<a name=\"ex1answer\">Answers to Exercise 1</a>"
755+
"<a id=\"ex1answer\">Answers to Exercise 1</a>"
756756
]
757757
},
758758
{
@@ -809,7 +809,7 @@
809809
"source": [
810810
"<a href=\"#back1\">Back to Exercise 1</a>\n",
811811
"\n",
812-
"<a name=\"ex2answer\">Answers to Exercise 2</a>"
812+
"<a id=\"ex2answer\">Answers to Exercise 2</a>"
813813
]
814814
},
815815
{
@@ -859,7 +859,7 @@
859859
"source": [
860860
"<a href=\"#back2\">Back to Exercise 2</a>\n",
861861
"\n",
862-
"<a name=\"ex3answer\">Answers to Exercise 3</a>"
862+
"<a id=\"ex3answer\">Answers to Exercise 3</a>"
863863
]
864864
},
865865
{
@@ -896,7 +896,7 @@
896896
"source": [
897897
"<a href=\"#back3\">Back to Exercise 3</a>\n",
898898
"\n",
899-
"<a name=\"ex4answer\">Answers to Exercise 4</a>"
899+
"<a id=\"ex4answer\">Answers to Exercise 4</a>"
900900
]
901901
},
902902
{
@@ -956,7 +956,7 @@
956956
"source": [
957957
"<a href=\"#back4\">Back to Exercise 4</a>\n",
958958
"\n",
959-
"<a name=\"ex5answer\">Answers to Exercise 5</a>"
959+
"<a id=\"ex5answer\">Answers to Exercise 5</a>"
960960
]
961961
},
962962
{
@@ -996,7 +996,7 @@
996996
"source": [
997997
"<a href=\"#back5\">Back to Exercise 5</a>\n",
998998
"\n",
999-
"<a name=\"ex6answer\">Answers to Exercise 6</a>"
999+
"<a id=\"ex6answer\">Answers to Exercise 6</a>"
10001000
]
10011001
},
10021002
{

0 commit comments

Comments
 (0)