Skip to content

Commit

Permalink
Add new exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Jul 3, 2023
1 parent f16740e commit e83d987
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 27 deletions.
97 changes: 82 additions & 15 deletions day-02/exercise_set_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Linear Algebra and Probability Distributions Exercises"
"# Python and Linear Algebra Exercises"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div align=\"right\"><button><a href=\"https://colab.research.google.com/github/QuantEcon/workshop.africa-july2023/blob/main/day-02/exercise_set_2.ipynb\"><img src=\"\" heght=\"10px\"/><img\n",
"<div align=\"right\"><button><a href=\"https://colab.research.google.com/github/QuantEcon/workshop.africa-july2023/blob/main/day-02/exercise_set_2_with_solution.ipynb\"><img src=\"\" heght=\"10px\"/><img\n",
" src=\"https://colab.research.google.com/assets/colab-badge.svg\"\n",
" alt=\"open with Colab\" width=\"100px\"/></a></button></div>"
]
Expand All @@ -21,7 +21,7 @@
"metadata": {},
"source": [
"#### Written for the QuantEcon Africa Workshop (July 2023)\n",
"#### Author: [John Stachurski](http://johnstachurski.net/) and [Hengcheng Zhang](https://github.com/HengchengZhang)"
"#### Author: [John Stachurski](http://johnstachurski.net/) , [Hengcheng Zhang](https://github.com/HengchengZhang), and [Smit Lunagariya](https://github.com/Smit-create)"
]
},
{
Expand All @@ -42,6 +42,72 @@
"source": [
"### Exercise 1\n",
"\n",
"Complete the following function that returns the number of odd elements in the given list."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def get_odd_num_from_list(nums):\n",
" # TODO: Finish this function\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Test the solution\n",
"try:\n",
" assert get_odd_num_from_list([1, 2, 3]) == 2\n",
" assert get_odd_num_from_list(list(range(1, 20))) == 10\n",
" assert get_odd_num_from_list(list(range(0, 20, 2))) == 0\n",
" print(\"Congratulations!\")\n",
"except:\n",
" print(\"Wrong answer, please check your code again.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 2\n",
"\n",
"Consider the following time-series\n",
"\n",
"$$\n",
" a_{t+1} = (0.5 + r)a_t - br^2a_t\n",
"$$\n",
"\n",
"Assume that $r=0.05$, $b=100$ and $a_0=1.5$.\n",
"\n",
"Generate and plot the sequence $a_0, a_1, ..., a_T$.\n",
"\n",
"Use NumPy arrays to store the sequence $a$.\n",
"\n",
"Use $T=25$."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# TODO: Write your solution here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 3\n",
"\n",
"Warm up on NumPy Basics.\n",
"\n",
"Feel free to refer to the [numpy documentation](https://numpy.org/doc/stable/reference/index.html) for API."
Expand All @@ -51,7 +117,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 1.1**: Write a function that creates numpy array from the given list/tuple."
"**Exercise 3.1**: Write a function that creates numpy array from the given list/tuple."
]
},
{
Expand Down Expand Up @@ -84,7 +150,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 1.2**: Write a function to return the transpose of the given matrix."
"**Exercise 3.2**: Write a function to return the transpose of the given matrix."
]
},
{
Expand Down Expand Up @@ -116,7 +182,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 1.3**: Write a function to return the inverse of the given matrix."
"**Exercise 3.3**: Write a function to return the inverse of the given matrix."
]
},
{
Expand Down Expand Up @@ -150,7 +216,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 1.4**: Write a function to compute the norm of the vector."
"**Exercise 3.4**: Write a function to compute the norm of the vector."
]
},
{
Expand Down Expand Up @@ -182,7 +248,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 1.5**: Write a function that returns the standardized vector of the given vector such that the mean is $0$ and standard deviation is $1$. Mathematically:\n",
"**Exercise 3.5**: Write a function that returns the standardized vector of the given vector such that the mean is $0$ and standard deviation is $1$. Mathematically:\n",
"$$\n",
"\\forall x_{i}\\in x:\\hspace{1em}x_{i}^{\\prime}=\\frac{x_{i}-\\mu}{\\sigma}\n",
"$$"
Expand Down Expand Up @@ -220,14 +286,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 2"
"### Exercise 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 2.1**: Write a function that takes two numpy vectors as an argument and returns `True` if they are orthogonal else returns `False`.\n",
"**Exercise 4.1**: Write a function that takes two numpy vectors as an argument and returns `True` if they are orthogonal else returns `False`.\n",
"\n",
"*Note: Two vectors are called orthogonal if their inner product is zero.*"
]
Expand Down Expand Up @@ -262,7 +328,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Question 2.2**: Write a function to check whether the given matrix is symmetric or not."
"**Exercise 4.2**: Write a function to check whether the given matrix is symmetric or not."
]
},
{
Expand All @@ -271,7 +337,7 @@
"metadata": {},
"outputs": [],
"source": [
"def is_symmetric(x, y):\n",
"def is_symmetric(x):\n",
" # TODO: Finish this function\n",
" pass"
]
Expand All @@ -296,7 +362,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercise 3\n"
"### Exercise 5"
]
},
{
Expand All @@ -315,14 +381,15 @@
"For $ t = 1, 2, 3, \\ldots, T $ suppose that\n",
"\n",
"\n",
"\n",
"$$\n",
"y_{t} = \\alpha_{0} + \\alpha_{1} y_{t-1}\n",
"$$\n",
"\n",
"where we assume that $ y_0 = 1$, $\\alpha_{0}=5$, and $\\alpha_{1}=1.2$.\n",
"\n",
"\n",
"**Exercise 3.1**: Use the matrix algebra to solve the above time series equation, and plot the solution.\n",
"Use the matrix algebra to solve the above time series equation, and plot the solution.\n",
"\n",
"*Hint:*\n",
"\n",
Expand Down Expand Up @@ -389,7 +456,7 @@
"metadata": {},
"outputs": [],
"source": [
"# TODO: Write your code here"
"# TODO: Write your solution here"
]
}
],
Expand Down
Loading

0 comments on commit e83d987

Please sign in to comment.