{ "cells": [ { "cell_type": "markdown", "id": "b55a0ff2", "metadata": {}, "source": [ "# Homework Assignment 2" ] }, { "cell_type": "markdown", "id": "6ea8e741", "metadata": {}, "source": [ "*Deadline: March 23, 2025. Your answer to the assignment must be written by hand and uploaded as a pdf to \"Assignments\" on Learn. Read the rules here: [](afsnit:regler-hjemafl). You may use a calculator or similar tools for simple calculations, e.g., calculating $P_4(1/2)$.*\n", "\n", "> **Remember, all answers must be justified and well-reasoned.**" ] }, { "cell_type": "markdown", "id": "331a14db", "metadata": {}, "source": [ "## Exercise 1: Computation of Cosine Values" ] }, { "cell_type": "markdown", "id": "4f8e8f38", "metadata": {}, "source": [ "In Python the value of e.g. $\\cos(\\sqrt{17})$ is computed approximatively with the call:\n", " \n", "```python\n", "import math\n", "\n", "print(math.cos(math.sqrt(17)))\n", "```\n", "\n", "But how does a computer actually find this approximation? A computer either uses a *precomputed lookup table* or approximating polynomials or a mix. In this exercise we will study how the computer would carry this out using Taylor polynomials. \n", "\n", "We consider a function $f:\\mathbb{R} \\rightarrow \\mathbb{R}$ given by the expression:\n", "\n", "\\begin{equation*}\n", " f(x)=\\cos (x).\n", "\\end{equation*}" ] }, { "cell_type": "markdown", "id": "69bd672b", "metadata": {}, "source": [ "### Question a" ] }, { "cell_type": "markdown", "id": "b895c166", "metadata": {}, "source": [ "Determine the approximating polynomial $P_4 = P_{4,f,x_0}$ of degree (no higher than) 4 with expansion point $x_0 = 0$ for the cosinus function." ] }, { "cell_type": "markdown", "id": "51eee2b5", "metadata": {}, "source": [ "### Question b" ] }, { "cell_type": "markdown", "id": "5b9df301", "metadata": {}, "source": [ "Use the polynomial $P_4$ you have found in the previous question to give an approximated value of $\\cos(1/2)$, and estimate how far the found value is from the exact value.\n", "% How large is the error at $x=\\pi/2$? (By \"error\" we mean the difference between $P_4(\\pi/2)$ and $\\cos(\\pi/2)$)" ] }, { "cell_type": "markdown", "id": "ef64f692", "metadata": {}, "source": [ "### Question c" ] }, { "cell_type": "markdown", "id": "bf33c687", "metadata": {}, "source": [ "Let $I = [-\\pi/2, \\pi/2]$. Use Theorem 4.3.3 to show that \n", "\n", "\\begin{equation*}\n", " \\lvert \\cos(x) - P_4(x) \\rvert \\le \\frac{(\\pi/2)^5}{5!} < \\frac{2^5}{5!} \n", "\\end{equation*}\n", "\n", "for all $x \\in [-\\pi/2, \\pi/2]$. Explain in your own words what the number\n", "\n", "\\begin{equation*}\n", " \\max_{x \\in [-\\pi/2, \\pi/2]} \\lvert \\cos(x) - P_4(x) \\rvert\n", "\\end{equation*}\n", "\n", "describes." ] }, { "cell_type": "markdown", "id": "794f40c4", "metadata": {}, "source": [ "### Question d" ] }, { "cell_type": "markdown", "id": "dcc8d55c", "metadata": {}, "source": [ "Show that the $K$'th-degree Taylor polynomial $P_K$ with the expansion point $x_0 = 0$ for the cosinus function fulfills\n", "\n", "\\begin{equation*}\n", " \\lvert \\cos(x) - P_K(x) \\rvert < \\frac{2^{K+1}}{(K+1)!} \n", "\\end{equation*}\n", "\n", "for all $x \\in [-\\pi/2, \\pi/2]$. Determine $K$ such that the error is smaller than $10^{-10}$. *By \"error\" we mean the numerical difference between $P_K(x)$ and $\\cos(x)$ for $x \\in [-\\pi/2, \\pi/2]$*. \n", "\n", "```{hint}\n", ":class: dropdown\n", "You do not need to calculate $P_K(x)$. \n", "\n", "When you are trying to determine $K$, it is enough to look at the right-hand side $\\frac{2^{K+1}}{(K+1)!}$. You might need a calculator or similar tool. \n", "```" ] }, { "cell_type": "markdown", "id": "cb2dbfa8", "metadata": {}, "source": [ "### Question e" ] }, { "cell_type": "markdown", "id": "fe64de58", "metadata": {}, "source": [ "We can now with fairly good accuracy compute $\\cos(x)$ for any $x \\in [-\\pi/2, \\pi/2]$ by use of the Taylor polynomial $P_K$ with expansion point $x_0 = 0$ (for a fixed, but sufficiently large chosen $K$). But how do we calculate an approximated value of $\\cos$ on the rest of the real line, meaning when $x$ is outside the interval $[-\\pi/2, \\pi/2]$?" ] }, { "cell_type": "markdown", "id": "4cbe7781", "metadata": {}, "source": [ "In order to answer this question we let $x \\in [-\\pi/2, \\pi/2]$ be given and assume that the value of $\\cos(x)$ is known (i.e. calculated approximately as above). Explain how you for an arbitrarily given $y \\in \\mathbb{R}$ now can find the value of $\\cos(y)$.\n", "\n", "```{hint}\n", ":class: dropdown\n", "You only need some properties of the cosine function. Draw the graph of $\\cos$ over $[-2\\pi,2\\pi]$. Use the fact that $\\cos$ is periodic and \"odd\" (not even) around $x = \\pi/2$. \n", "```" ] }, { "cell_type": "markdown", "id": "065dd561", "metadata": {}, "source": [ "## Exercise 2: L'Hôpital's Rule and Taylor's Limit Formula" ] }, { "cell_type": "markdown", "id": "f64e5cfc", "metadata": {}, "source": [ "L'Hôpital's rule is used for determination of limits of the type $\\lim_{x \\to a} \\frac{f(x)}{g(x)}$ where $f(a)=0$ and $g(a)=0$. The limit value is in this case said to be of the type $\\frac{0}{0}$. The rule is stated as follows:\n", "\n", "\n", "```{admonition} Theorem (L'Hôpital's Rule)\n", "Let $I \\subseteq \\mathbb{R}$ be an open interval, let $a \\in I$, and let $f$ and $g$ be differentiable on $I\\setminus \\{a\\}$. Assume the following:\n", "\n", "1. $\\lim_{x \\to a} f(x) = \\lim_{x \\to a} g(x) = 0$\n", "2. $g'(x) \\neq 0$ for $x \\in I \\setminus \\{a\\}$\n", "3. The limit $\\lim_{x \\to a} \\frac{f'(x)}{g'(x)}$ exists\n", "\n", "Then it holds that:\n", "\n", "\\begin{equation*}\n", " \\lim_{x \\to a} \\frac{f(x)}{g(x)} = \\lim_{x \\to a} \\frac{f'(x)}{g'(x)}.\n", "\\end{equation*}\n", "```\n", "\n", "Consider the limit:\n", "\n", "\\begin{equation*}\n", " \\lim_{x \\to 0} \\frac{\\ln(1 + x)}{1 - \\sqrt{1 + x}}.\n", "\\end{equation*}" ] }, { "cell_type": "markdown", "id": "610db9fd", "metadata": {}, "source": [ "### Question a" ] }, { "cell_type": "markdown", "id": "05c5f46b", "metadata": {}, "source": [ "Show that this limit is of the type $\\frac{0}{0}$." ] }, { "cell_type": "markdown", "id": "b02820b5", "metadata": {}, "source": [ "### Question b" ] }, { "cell_type": "markdown", "id": "431bdabf", "metadata": {}, "source": [ "Check that $g'(x) \\neq 0$ for $x$ close to $0$, so that we can use the rule." ] }, { "cell_type": "markdown", "id": "f83fca1e", "metadata": {}, "source": [ "### Question c" ] }, { "cell_type": "markdown", "id": "e3526f33", "metadata": {}, "source": [ "Use L'Hôpital's rule to determine the limit value." ] }, { "cell_type": "markdown", "id": "cae52a7b", "metadata": {}, "source": [ "### Question d" ] }, { "cell_type": "markdown", "id": "531d8148", "metadata": {}, "source": [ "Determine this same limit limit using Taylor's limit formula for $\\ln(1 + x)$ and $\\sqrt{1 + x}$ up to a fitting order." ] }, { "cell_type": "markdown", "id": "dcc3f056", "metadata": {}, "source": [ "### Question e" ] }, { "cell_type": "markdown", "id": "c269581a", "metadata": {}, "source": [ "Prove L'Hôpital's rule using Taylor's limit formula for general functions $f(x)$ and $g(x)$ that fulfill the assumptions in the theorem.\n", "\n", "\n", "```{hint}\n", ":class: dropdown\n", "Use a Taylor expansion of $f(x)$ and $g(x)$ around $ x = a $ up to the first order with *epsilon* functions:\n", "\\begin{equation*}\n", " f(x) = f(a) + f'(a)(x-a) + \\epsilon_f(x-a)(x-a),\n", "\\end{equation*}\n", "and\n", "\\begin{equation*}\n", " g(x) = g(a) + g'(a)(x-a) + \\epsilon_g(x-a)(x-a).\n", "\\end{equation*}\n", "\n", "```\n", "\n", "```{admonition} Update March 12\n", "You may assume that $g'(a) \\neq 0$. This is often the case (for example, in our application), and it simplifies the proof.\n", "```\n", "\n", "```{hint}\n", ":class: dropdown\n", "Use what you know about $f(a)$ and $g(a)$.\n", "```" ] }, { "cell_type": "markdown", "id": "b53a7d4e", "metadata": {}, "source": [ "## Exercise 3: Image Set of a Continuous, Differentiable Function" ] }, { "cell_type": "markdown", "id": "93768786", "metadata": {}, "source": [ "Let $B$ be the set $B=\\left\\{ (x_1 , x_2) \\in \\mathbb{R}^2 \\mid x_1^2 + x_2^2 \\leq 2 \\wedge x_1 \\leq 0 \\right\\}$.\n", "\n", "A function $f:B \\rightarrow \\mathbb{R}$ is given by: \n", "\n", "\\begin{equation*}\n", " f(x_1 ,x_2) = x_1^2​ + x_2^2 + x_1​ + 1.\n", "\\end{equation*}\n", "\n", "State the image set of $f$." ] }, { "cell_type": "markdown", "id": "3a75f44f", "metadata": {}, "source": [ "## Exercise 4: Local Extrema" ] }, { "cell_type": "markdown", "id": "4481f23d", "metadata": {}, "source": [ "A function $f:\\mathbb{R}^2 \\rightarrow \\mathbb{R}$ is given by: \n", "\n", "\\begin{equation*}\n", "f(x_1 ,x_2 )=x_1^2 - 2x_1 +3x_2^5 - 5x_2^3.\n", "\\end{equation*}" ] }, { "cell_type": "markdown", "id": "66198c70", "metadata": {}, "source": [ "### Question a" ] }, { "cell_type": "markdown", "id": "87c0b986", "metadata": {}, "source": [ "Find all stationary points for $f$." ] }, { "cell_type": "markdown", "id": "952d8eaa", "metadata": {}, "source": [ "### Question b" ] }, { "cell_type": "markdown", "id": "d72ccc32", "metadata": {}, "source": [ "State for each stationary point whether it is a local maximum, a local minimum or a saddle point." ] }, { "cell_type": "markdown", "id": "2724d2ee", "metadata": {}, "source": [ "### Question c" ] }, { "cell_type": "markdown", "id": "fc6f1b03", "metadata": {}, "source": [ "For each stationary point, plot the function in Python along with the approximating polynomial $P_{2}$ of degree (no high than) 2 expanded from the stationary point." ] } ], "metadata": { "jupytext": { "formats": "ipynb,md:myst", "text_representation": { "extension": ".md", "format_name": "myst", "format_version": 0.13, "jupytext_version": "1.16.0" } }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "source_map": [ 13, 17, 23, 27, 45, 49, 53, 57, 62, 66, 82, 86, 106, 110, 114, 123, 127, 152, 156, 160, 164, 168, 172, 176, 180, 184, 188, 215, 219, 231, 235, 243, 247, 251, 255, 259, 263 ] }, "nbformat": 4, "nbformat_minor": 5 }