{ "cells": [ { "cell_type": "markdown", "id": "d73c7ab5", "metadata": {}, "source": [ "Quiz 2 MCS 471, on Friday 2 September 2022, due 10:50am." ] }, { "cell_type": "markdown", "id": "81cf59ec", "metadata": {}, "source": [ "Consider the polynomials\n", "\n", "$$\n", " p(x) = (x-1)(x-2)(x-3)\n", "$$\n", "\n", "and\n", "\n", "$$\n", " q(x) = (x-1.99999)(x-2)(x-2.00001).\n", "$$\n", "\n", "Compute the condition number for 2 as root of $p$ and 2 as root of $q$." ] }, { "cell_type": "markdown", "id": "552c338c", "metadata": {}, "source": [ "Write one sentence to compare the condition numbers." ] }, { "cell_type": "markdown", "id": "b3cbfa83", "metadata": {}, "source": [ "# Answer" ] }, { "cell_type": "markdown", "id": "3c990cfd", "metadata": {}, "source": [ "We evaluate the formula\n", "\n", "$$\n", " \\kappa = \\frac{|f|}{|2 f'(2)|}.\n", "$$\n", "\n", "for $f = p$ and $f = q$." ] }, { "cell_type": "code", "execution_count": 1, "id": "3de2c263", "metadata": {}, "outputs": [], "source": [ "using Polynomials" ] }, { "cell_type": "code", "execution_count": 2, "id": "ed116108", "metadata": {}, "outputs": [ { "data": { "text/html": [ "-6 + 11∙x - 6∙x2 + x3" ], "text/latex": [ "$-6 + 11\\cdot x - 6\\cdot x^{2} + x^{3}$" ], "text/plain": [ "Polynomial(-6 + 11*x - 6*x^2 + x^3)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = fromroots([1, 2, 3])" ] }, { "cell_type": "code", "execution_count": 3, "id": "c7205191", "metadata": {}, "outputs": [ { "data": { "text/html": [ "11 - 12∙x + 3∙x2" ], "text/latex": [ "$11 - 12\\cdot x + 3\\cdot x^{2}$" ], "text/plain": [ "Polynomial(11 - 12*x + 3*x^2)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dp = derivative(p)" ] }, { "cell_type": "code", "execution_count": 12, "id": "4db54563", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6.0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mp = maximum([abs(p(x)) for x=0.0:0.01:4.0])" ] }, { "cell_type": "code", "execution_count": 9, "id": "39cef47e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "kp = abs(mp/(2*dp(2)))" ] }, { "cell_type": "code", "execution_count": 10, "id": "d2f698d9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "-7.9999999998 + 11.999999999900002∙x - 6.0∙x2 + 1.0∙x3" ], "text/latex": [ "$-7.9999999998 + 11.999999999900002\\cdot x - 6.0\\cdot x^{2} + 1.0\\cdot x^{3}$" ], "text/plain": [ "Polynomial(-7.9999999998 + 11.999999999900002*x - 6.0*x^2 + 1.0*x^3)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q = fromroots([1.99999, 2, 2.00001])" ] }, { "cell_type": "code", "execution_count": 11, "id": "bb3bcb3d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "11.999999999900002 - 12.0∙x + 3.0∙x2" ], "text/latex": [ "$11.999999999900002 - 12.0\\cdot x + 3.0\\cdot x^{2}$" ], "text/plain": [ "Polynomial(11.999999999900002 - 12.0*x + 3.0*x^2)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dq = derivative(q)" ] }, { "cell_type": "code", "execution_count": 13, "id": "894d2b36", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7.999999999800007" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mq = maximum([abs(q(x)) for x = 0.0:0.01:4.0])" ] }, { "cell_type": "code", "execution_count": 14, "id": "2f95e711", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4.0000707244625626e10" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "kq = abs(mq/(2*dq(2)))" ] }, { "cell_type": "markdown", "id": "2b9d6786", "metadata": {}, "source": [ "Observe that the condition number of 2 as root of $q$ is $4 \\times 10^{10}$, whereas the condition number of 2 as root of $p$ is 3." ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.8.0", "language": "julia", "name": "julia-1.8" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.8.0" } }, "nbformat": 4, "nbformat_minor": 5 }