Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions notebook1-4_test/notebook1-4_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### <a name=\"ex1\"></a>Exercise 1\n",
"### <a id=\"ex1\"></a>Exercise 1\n",
"\n",
"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",
"\n",
Expand Down Expand Up @@ -60,7 +60,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### <a name=\"ex2\"></a>Exercise 2\n",
"### <a id=\"ex2\"></a>Exercise 2\n",
"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",
"\n",
"Demonstrate that your function works by using the file `numbers2016.txt` and execute the following line of code:\n",
Expand All @@ -86,7 +86,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### <a name=\"ex3\"></a>Exercise 3\n",
"### <a id=\"ex3\"></a>Exercise 3\n",
"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`"
]
},
Expand Down Expand Up @@ -134,7 +134,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### <a name=\"ex5\"></a>Exercise 5\n",
"### <a id=\"ex5\"></a>Exercise 5\n",
"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."
]
},
Expand Down Expand Up @@ -163,31 +163,31 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<a name=\"ex1answer\">Answer to Exercise 1</a>\n",
"<a id=\"ex1answer\">Answer to Exercise 1</a>\n",
"\n",
"You probably know what this should look like\n",
"\n",
"<a href=\"#ex1\">Back to Exercise 1</a>\n",
"\n",
"<a name=\"ex2answer\">Answer to Exercise 2</a>\n",
"<a id=\"ex2answer\">Answer to Exercise 2</a>\n",
"\n",
"93\n",
"\n",
"<a href=\"#ex2\">Back to Exercise 2</a>\n",
"\n",
"<a name=\"ex3answer\">Answer to Exercise 3</a>\n",
"<a id=\"ex3answer\">Answer to Exercise 3</a>\n",
"\n",
"Q1: 4, Q2: 4, Q3: 5, Q4:3, Q5:5, Q6:5, Q7:4, Q8:4\n",
"\n",
"<a href=\"#ex3\">Back to Exercise 3</a>\n",
"\n",
"<a name=\"ex4answer\">Answer to Exercise 4</a>\n",
"<a id=\"ex4answer\">Answer to Exercise 4</a>\n",
"\n",
"Your graph should look like the provided figure\n",
"\n",
"<a href=\"#ex4\">Back to Exercise 4</a>\n",
"\n",
"<a name=\"ex5answer\">Answer to Exercise 5</a>\n",
"<a id=\"ex5answer\">Answer to Exercise 5</a>\n",
"\n",
"31.3\n",
"\n",
Expand Down
24 changes: 12 additions & 12 deletions notebook10_continuous_random_variables/py_exploratory_comp_10.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 1: <a name=\"back1\"></a>First histogram\n",
"### Exercise 1: <a id=\"back1\"></a>First histogram\n",
"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. "
]
},
Expand Down Expand Up @@ -181,7 +181,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Expercise 2. <a name=\"back2\"></a>Lower and upper quartile\n",
"### Expercise 2. <a id=\"back2\"></a>Lower and upper quartile\n",
"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."
]
},
Expand Down Expand Up @@ -391,7 +391,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 3. <a name=\"back3\"></a>Loading experimental data and basic operations\n",
"### Exercise 3. <a id=\"back3\"></a>Loading experimental data and basic operations\n",
"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",
"\n",
"* Determine and report the minimum and maximum measured values of the bending strength. \n",
Expand All @@ -417,7 +417,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 4. <a name=\"back4\"></a>Boxplot of moisture content\n",
"### Exercise 4. <a id=\"back4\"></a>Boxplot of moisture content\n",
"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."
]
},
Expand Down Expand Up @@ -453,7 +453,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 5. <a name=\"back5\"></a>Histogram of bending strength\n",
"### Exercise 5. <a id=\"back5\"></a>Histogram of bending strength\n",
"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."
]
},
Expand All @@ -475,7 +475,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 6. <a name=\"back6\"></a>Normal distribution for bending strength\n",
"### Exercise 6. <a id=\"back6\"></a>Normal distribution for bending strength\n",
"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"
]
},
Expand Down Expand Up @@ -504,7 +504,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<a name=\"ex1answer\">Answers to Exercise 1</a>"
"<a id=\"ex1answer\">Answers to Exercise 1</a>"
]
},
{
Expand Down Expand Up @@ -542,7 +542,7 @@
"source": [
"<a href=\"#back1\">Back to Exercise 1</a>\n",
"\n",
"<a name=\"ex2answer\">Answers to Exercise 2</a>"
"<a id=\"ex2answer\">Answers to Exercise 2</a>"
]
},
{
Expand Down Expand Up @@ -573,7 +573,7 @@
"source": [
"<a href=\"#back2\">Back to Exercise 2</a>\n",
"\n",
"<a name=\"ex3answer\">Answers to Exercise 3</a>"
"<a id=\"ex3answer\">Answers to Exercise 3</a>"
]
},
{
Expand All @@ -596,7 +596,7 @@
"source": [
"<a href=\"#back3\">Back to Exercise 3</a>\n",
"\n",
"<a name=\"ex4answer\">Answers to Exercise 4</a>"
"<a id=\"ex4answer\">Answers to Exercise 4</a>"
]
},
{
Expand Down Expand Up @@ -626,7 +626,7 @@
"source": [
"<a href=\"#back4\">Back to Exercise 4</a>\n",
"\n",
"<a name=\"ex5answer\">Answers to Exercise 5</a>"
"<a id=\"ex5answer\">Answers to Exercise 5</a>"
]
},
{
Expand All @@ -648,7 +648,7 @@
"source": [
"<a href=\"#back5\">Back to Exercise 5</a>\n",
"\n",
"<a name=\"ex6answer\">Answers to Exercise 6</a>"
"<a id=\"ex6answer\">Answers to Exercise 6</a>"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 1: <a name=\"back1\"></a>First histogram\n",
"### Exercise 1: <a id=\"back1\"></a>First histogram\n",
"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. "
]
},
Expand Down Expand Up @@ -262,7 +262,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Expercise 2. <a name=\"back2\"></a>Lower and upper quartile\n",
"### Expercise 2. <a id=\"back2\"></a>Lower and upper quartile\n",
"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."
]
},
Expand Down Expand Up @@ -639,7 +639,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 3. <a name=\"back3\"></a>Loading experimental data and basic operations\n",
"### Exercise 3. <a id=\"back3\"></a>Loading experimental data and basic operations\n",
"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",
"\n",
"* Determine and report the minimum and maximum measured values of the bending strength. \n",
Expand All @@ -665,7 +665,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 4. <a name=\"back4\"></a>Boxplot of moisture content\n",
"### Exercise 4. <a id=\"back4\"></a>Boxplot of moisture content\n",
"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."
]
},
Expand Down Expand Up @@ -701,7 +701,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 5. <a name=\"back5\"></a>Histogram of bending strength\n",
"### Exercise 5. <a id=\"back5\"></a>Histogram of bending strength\n",
"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."
]
},
Expand All @@ -723,7 +723,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 6. <a name=\"back6\"></a>Normal distribution for bending strength\n",
"### Exercise 6. <a id=\"back6\"></a>Normal distribution for bending strength\n",
"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"
]
},
Expand Down Expand Up @@ -752,7 +752,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<a name=\"ex1answer\">Answers to Exercise 1</a>"
"<a id=\"ex1answer\">Answers to Exercise 1</a>"
]
},
{
Expand Down Expand Up @@ -809,7 +809,7 @@
"source": [
"<a href=\"#back1\">Back to Exercise 1</a>\n",
"\n",
"<a name=\"ex2answer\">Answers to Exercise 2</a>"
"<a id=\"ex2answer\">Answers to Exercise 2</a>"
]
},
{
Expand Down Expand Up @@ -859,7 +859,7 @@
"source": [
"<a href=\"#back2\">Back to Exercise 2</a>\n",
"\n",
"<a name=\"ex3answer\">Answers to Exercise 3</a>"
"<a id=\"ex3answer\">Answers to Exercise 3</a>"
]
},
{
Expand Down Expand Up @@ -896,7 +896,7 @@
"source": [
"<a href=\"#back3\">Back to Exercise 3</a>\n",
"\n",
"<a name=\"ex4answer\">Answers to Exercise 4</a>"
"<a id=\"ex4answer\">Answers to Exercise 4</a>"
]
},
{
Expand Down Expand Up @@ -956,7 +956,7 @@
"source": [
"<a href=\"#back4\">Back to Exercise 4</a>\n",
"\n",
"<a name=\"ex5answer\">Answers to Exercise 5</a>"
"<a id=\"ex5answer\">Answers to Exercise 5</a>"
]
},
{
Expand Down Expand Up @@ -996,7 +996,7 @@
"source": [
"<a href=\"#back5\">Back to Exercise 5</a>\n",
"\n",
"<a name=\"ex6answer\">Answers to Exercise 6</a>"
"<a id=\"ex6answer\">Answers to Exercise 6</a>"
]
},
{
Expand Down
Loading