{ "cells": [ { "cell_type": "markdown", "id": "d1369dae", "metadata": {}, "source": [ "---\n", "format:\n", " html: default\n", "---\n", "\n", "# A1: Notebooks {.unnumbered}\n", "\n", "Assignment 1: Jupyter Notebooks, LaTeX, Julia & Prerequisites
\n", "Published: Wed 9 Sept\n", "\n", "
\n", "Note:\n", "\n", "
\n", "\n", "
\n", " \n", " Download (.ipynb)\n", " \n", "
\n", "\n", "## A: Jupyter Notebooks {.unnumbered}" ] }, { "cell_type": "markdown", "id": "1cdd630f", "metadata": {}, "source": [ "
\n", "Tip:\n", "You may do this part with the help from your classmates\n", "
\n", "\n", "***Exercise 1.***\n", "\n", "* Follow the steps [here](https://jackrthomas.github.io/Math5485/appendix/installing-julia.html) to install Julia and Jupyter, \n", "* Upload and run this .ipynb file, \n", "* Double click on the following cell to replace YOUR NAME HERE with your name" ] }, { "cell_type": "code", "execution_count": 1, "id": "ccfc9a8e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"YOUR NAME HERE\"" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Name = \"YOUR NAME HERE\"" ] }, { "cell_type": "markdown", "id": "626e8c83", "metadata": {}, "source": [ "## B: $\\LaTeX$ {.unnumbered}" ] }, { "cell_type": "markdown", "id": "7a01644d", "metadata": {}, "source": [ "***Exercise 2. Taylor expansion*** \n", "\n", "a. Write down the degree $n$ Taylor polynomial of $f:\\mathbb R \\to \\mathbb R$ about some point $a$.\n", "\n", "
Answer. \n", "\n", "\\begin{align}\n", " T_nf(x) = ....\n", " \\nonumber \n", "\\end{align}\n", "\n", "
\n", "\n", "b. Write down your favourite form of the remainder $R_n(x) := f(x) - T_nf(x)$\n", "\n", "
Answer. \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\\begin{align}\n", " R_n(x) = ....\n", " \\nonumber \n", "\\end{align}\n", "
\n", "\n", "c. Consider the function $f(x) := \\frac{e^x - 1}{x}$. Use Taylor expansion of $e^x$ to evaluate $\\lim_{x\\to 0} f(x)$.\n", "\n", "
Answer. \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
" ] }, { "cell_type": "markdown", "id": "e6e898c0", "metadata": {}, "source": [ "## C. Julia {.unnumbered}\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "a2de3804", "metadata": {}, "outputs": [], "source": [ "using Plots" ] }, { "cell_type": "markdown", "id": "650a93fa", "metadata": {}, "source": [ "***Exercise 3. Archimedes' method for computing (lower bounds to) $\\pi$.*** \n", "\n", "Recall that $\\pi$ is half the circumference of the unit circle. Let $P_n$ be the inscribed regular $n$-gon inside the unit circle and notice that its perimeter satisfies $2 \\pi_n \\leq 2 \\pi$. \n", "\n", "* ✍️ Explain why $\\pi_n = n \\sin \\frac{\\pi}{n}$, \n", "* 💻 What is the absolute error when approximating $\\pi$ with $\\pi_{2026}$? \n", "* ✍️ Use Taylor expansion of $\\sin$ to explain why $(\\pi_n)$ converges with rate $O(n^{-2})$, \n", "* 💻 Verify this rate of convergence with a plot. \n", "* ✍️ For what $n$ is $\\pi_n$ equal to $\\pi$ up to the first $2026$ significant decimal digits? \n", "\n", "
Answer. \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": 3, "id": "8657f54e", "metadata": {}, "outputs": [], "source": [ "# your answer here" ] }, { "cell_type": "markdown", "id": "17c1d9de", "metadata": {}, "source": [ "***Exercise 4. Subtractive Cancellation*** \n", "\n", "Take $f(x) := \\frac{e^x - 1}{x}$. Implementing this function directly is a bad idea due to subtractive cancellation (we will go through this in detail in week 2). Julia has the built-in function ```expm1``` which uses the Taylor expansion of $e^x$ (as you did in Exercise 2) to evaluate $e^x-1$ without subtractive cancellation. \n", "\n", "Here are two ways of evaluating $f(10^{-15})$:" ] }, { "cell_type": "code", "execution_count": 4, "id": "ad134ae2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1.1102230246251565, 1.0000000000000007)" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "g(x) = (exp(x)-1)/x \n", "h(x) = expm1(x)/x\n", "\n", "g_x, h_x = g(1e-15), h(1e-15)" ] }, { "cell_type": "markdown", "id": "dee2b16c", "metadata": {}, "source": [ "What are the relative errors between the mathematical value of $f(10^{-15})$ and the approximations ```g_x``` (naive formula) and ```h_x``` (Taylor expansion). \n", "\n", "You may use ```y``` defined in the code below as the \"exact\" value of $f(10^{-15})$ (which is correct to the first 100 significant digits)." ] }, { "cell_type": "code", "execution_count": 5, "id": "4ffbf2a7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0000000000000004" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "y = 1.000000000000000500000000000000166666666666666708333333333333341666666666666668055555555555555753968\n", "\n", "# YOUR CODE HERE" ] }, { "cell_type": "markdown", "id": "ced8f7cc", "metadata": {}, "source": [ "## D. Reflection {.unnumbered}\n", "\n", "**Goal:** Reflect on your learning strategies, track your workload, and help us improve future course material. \n", "**Format:** Short answer (Graded on completion: Complete / incomplete). \n", "**Time:** take 5-10 mins (this shouldn't take too long)\n", "\n", "Estimate the approximate hours you spent: \n", "* **Assignment:** ____ \n", "* **Reading notes/materials:** ____ \n", "* **Exercises:** ____ \n", "\n", "(Reminder: you should be spending around 8 hours per week on this course outside of the 4 hours of lectures)\n", "\n", "
Any other comments: \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "Take a moment to reflect on your learning over the past week:\n", "\n", "What was the easiest topic or task and why? Where did you struggle, and how did you overcome those challenges? Which resources (e.g. lecture notes, practice exercises, peer discussions, ...) helped you the most? How did you manage your time and workload (e.g., all at once, spread out over several days, or working with peers)? Looking back, what would you do differently if you were starting this week over today?\n", "\n", "
Comments: \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "(Optional) Any changes that would improve the lectures, exercises, or assignments for the future? You can also suggest things anonymously \n", " \n", " here\n", " (opens in a new tab)\n", " \n", "\n", "
Comments: \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\n" ] }, { "cell_type": "markdown", "id": "b6442027", "metadata": {}, "source": [ "## (E: Bonus exercises - not for credit) {.unnumbered}\n", "\n", "Catch up with the exercises from the lectures. If you have time, think about the following questions: \n", "\n", "In Exercise 4, $y$ is defined as $y = 1.0000000000000005....$ but the output is $y = 1.0000000000000004$. Why? How should you implement numbers with higher precision? \n", "\n", "Think about why the following method for computing $f(10^{-15})$ does not suffer from subtractive cancellation:" ] }, { "cell_type": "code", "execution_count": 6, "id": "2f782e44", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0000000000000004" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "j(y) = (y-1)/log(y) \n", "j_x = j(exp(1e-15))" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.12.6", "language": "julia", "name": "julia-1.12" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.12.6" } }, "nbformat": 4, "nbformat_minor": 5 }