{ "cells": [ { "cell_type": "markdown", "id": "5a09a7f6", "metadata": {}, "source": [ "# Exponencial function\n", "\n", "In this tutoial we show a few Padé approximants of $e^{x}\\,$ using infinite and finite precision." ] }, { "cell_type": "code", "execution_count": 119, "id": "28869892", "metadata": {}, "outputs": [], "source": [ "import sympy as sp\n", "from padepy import baker_algorithm as ba\n", "from padepy import direct_algorithm as da" ] }, { "cell_type": "code", "execution_count": 123, "id": "3c3818e7", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle e^{x}$" ], "text/plain": [ "exp(x)" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "var = sp.Symbol(\"x\")\n", "func = sp.exp(var)\n", "p = 3\n", "q = 3\n", "func" ] }, { "cell_type": "code", "execution_count": 124, "id": "f2fafb2d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Pade [3,3](x) stored at matrix index 6.\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\frac{\\frac{x^{3}}{120} + \\frac{x^{2}}{10} + \\frac{x}{2} + 1}{- \\frac{x^{3}}{120} + \\frac{x^{2}}{10} - \\frac{x}{2} + 1}$" ], "text/plain": [ "(x**3/120 + x**2/10 + x/2 + 1)/(-x**3/120 + x**2/10 - x/2 + 1)" ] }, "execution_count": 124, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pade, path = ba.pade(p, q, var, func, 0, False)\n", "pade" ] }, { "cell_type": "code", "execution_count": 125, "id": "7d43f619", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}\\frac{x^{6}}{720} + \\frac{x^{5}}{120} + \\frac{x^{4}}{24} + \\frac{x^{3}}{6} + \\frac{x^{2}}{2} + x + 1\\\\\\frac{x^{5}}{120} + \\frac{x^{4}}{24} + \\frac{x^{3}}{6} + \\frac{x^{2}}{2} + x + 1\\\\\\frac{\\frac{x^{5}}{720} + \\frac{x^{4}}{72} + \\frac{x^{3}}{12} + \\frac{x^{2}}{3} + \\frac{5 x}{6} + 1}{1 - \\frac{x}{6}}\\\\\\frac{\\frac{x^{4}}{120} + \\frac{x^{3}}{15} + \\frac{3 x^{2}}{10} + \\frac{4 x}{5} + 1}{1 - \\frac{x}{5}}\\\\\\frac{\\frac{x^{4}}{360} + \\frac{x^{3}}{30} + \\frac{x^{2}}{5} + \\frac{2 x}{3} + 1}{\\frac{x^{2}}{30} - \\frac{x}{3} + 1}\\\\\\frac{\\frac{x^{3}}{60} + \\frac{3 x^{2}}{20} + \\frac{3 x}{5} + 1}{\\frac{x^{2}}{20} - \\frac{2 x}{5} + 1}\\\\\\frac{\\frac{x^{3}}{120} + \\frac{x^{2}}{10} + \\frac{x}{2} + 1}{- \\frac{x^{3}}{120} + \\frac{x^{2}}{10} - \\frac{x}{2} + 1}\\\\\\frac{\\frac{x^{2}}{20} + \\frac{2 x}{5} + 1}{- \\frac{x^{3}}{60} + \\frac{3 x^{2}}{20} - \\frac{3 x}{5} + 1}\\\\\\frac{\\frac{x^{2}}{30} + \\frac{x}{3} + 1}{\\frac{x^{4}}{360} - \\frac{x^{3}}{30} + \\frac{x^{2}}{5} - \\frac{2 x}{3} + 1}\\\\\\frac{\\frac{x}{5} + 1}{\\frac{x^{4}}{120} - \\frac{x^{3}}{15} + \\frac{3 x^{2}}{10} - \\frac{4 x}{5} + 1}\\\\\\frac{\\frac{x}{6} + 1}{- \\frac{x^{5}}{720} + \\frac{x^{4}}{72} - \\frac{x^{3}}{12} + \\frac{x^{2}}{3} - \\frac{5 x}{6} + 1}\\\\\\frac{1}{- \\frac{x^{5}}{120} + \\frac{x^{4}}{24} - \\frac{x^{3}}{6} + \\frac{x^{2}}{2} - x + 1}\\\\\\frac{1}{\\frac{x^{6}}{720} - \\frac{x^{5}}{120} + \\frac{x^{4}}{24} - \\frac{x^{3}}{6} + \\frac{x^{2}}{2} - x + 1}\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[ x**6/720 + x**5/120 + x**4/24 + x**3/6 + x**2/2 + x + 1],\n", "[ x**5/120 + x**4/24 + x**3/6 + x**2/2 + x + 1],\n", "[ (x**5/720 + x**4/72 + x**3/12 + x**2/3 + 5*x/6 + 1)/(1 - x/6)],\n", "[ (x**4/120 + x**3/15 + 3*x**2/10 + 4*x/5 + 1)/(1 - x/5)],\n", "[ (x**4/360 + x**3/30 + x**2/5 + 2*x/3 + 1)/(x**2/30 - x/3 + 1)],\n", "[ (x**3/60 + 3*x**2/20 + 3*x/5 + 1)/(x**2/20 - 2*x/5 + 1)],\n", "[(x**3/120 + x**2/10 + x/2 + 1)/(-x**3/120 + x**2/10 - x/2 + 1)],\n", "[ (x**2/20 + 2*x/5 + 1)/(-x**3/60 + 3*x**2/20 - 3*x/5 + 1)],\n", "[ (x**2/30 + x/3 + 1)/(x**4/360 - x**3/30 + x**2/5 - 2*x/3 + 1)],\n", "[ (x/5 + 1)/(x**4/120 - x**3/15 + 3*x**2/10 - 4*x/5 + 1)],\n", "[(x/6 + 1)/(-x**5/720 + x**4/72 - x**3/12 + x**2/3 - 5*x/6 + 1)],\n", "[ 1/(-x**5/120 + x**4/24 - x**3/6 + x**2/2 - x + 1)],\n", "[ 1/(x**6/720 - x**5/120 + x**4/24 - x**3/6 + x**2/2 - x + 1)]])" ] }, "execution_count": 125, "metadata": {}, "output_type": "execute_result" } ], "source": [ "path" ] }, { "cell_type": "markdown", "id": "f82b93b2", "metadata": {}, "source": [ "It is possible to input a list with coefficients." ] }, { "cell_type": "code", "execution_count": 126, "id": "73f532ac", "metadata": {}, "outputs": [], "source": [ "from padepy import maclaurin as ma" ] }, { "cell_type": "code", "execution_count": 127, "id": "88ecfbb2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 1, 1/2, 1/6, 1/24, 1/120, 1/720, 1/5040]" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n = p + q + 1\n", "coeffs_list = ma.coefficients(n, var, func)\n", "coeffs_list" ] }, { "cell_type": "code", "execution_count": 128, "id": "9d97b9ad", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Pade [3,3](x) stored at matrix index 6.\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\frac{\\frac{x^{3}}{120} + \\frac{x^{2}}{10} + \\frac{x}{2} + 1}{- \\frac{x^{3}}{120} + \\frac{x^{2}}{10} - \\frac{x}{2} + 1}$" ], "text/plain": [ "(x**3/120 + x**2/10 + x/2 + 1)/(-x**3/120 + x**2/10 - x/2 + 1)" ] }, "execution_count": 128, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pade, path = ba.pade(p, q, var, coeffs_list, 0, False)\n", "pade" ] }, { "cell_type": "markdown", "id": "831cc33e", "metadata": {}, "source": [ "If we set $x=1$ we get an approximation of the value $e = 2.7182818284590452353602874713526624977572470936999595749669676277...$" ] }, { "cell_type": "code", "execution_count": 129, "id": "2406d733", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 2.71830985915493$" ], "text/plain": [ "2.71830985915493" ] }, "execution_count": 129, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e = 2.7182818284590452353602874713526624977572470936999595749669676277\n", "e_approx = pade.subs(var, 1.0)\n", "e_approx " ] }, { "cell_type": "code", "execution_count": 130, "id": "8e6558bf", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 2.80306958844179 \\cdot 10^{-5}$" ], "text/plain": [ "2.80306958844179e-5" ] }, "execution_count": 130, "metadata": {}, "output_type": "execute_result" } ], "source": [ "error = e_approx - e\n", "error" ] }, { "cell_type": "markdown", "id": "0e6050f8", "metadata": {}, "source": [ "We can also replace in path variable." ] }, { "cell_type": "code", "execution_count": 131, "id": "95d0df25", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}2.71805555555556\\\\2.71666666666667\\\\2.71833333333333\\\\2.71875\\\\2.71825396825397\\\\2.71794871794872\\\\2.71830985915493\\\\2.71875\\\\2.7182320441989\\\\2.71698113207547\\\\2.71844660194175\\\\2.72727272727273\\\\2.71698113207547\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[2.71805555555556],\n", "[2.71666666666667],\n", "[2.71833333333333],\n", "[ 2.71875],\n", "[2.71825396825397],\n", "[2.71794871794872],\n", "[2.71830985915493],\n", "[ 2.71875],\n", "[ 2.7182320441989],\n", "[2.71698113207547],\n", "[2.71844660194175],\n", "[2.72727272727273],\n", "[2.71698113207547]])" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e_approx_path = path.subs(var, 1.0)\n", "e_approx_path" ] }, { "cell_type": "markdown", "id": "b9000567", "metadata": {}, "source": [ "It is possible to work with floating precision." ] }, { "cell_type": "code", "execution_count": 132, "id": "8b4020a9", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Pade [3,3](x) stored at matrix index 6.\n" ] }, { "data": { "text/latex": [ "$\\displaystyle \\frac{0.00833333333333333 x^{3} + 0.09999999999999997 x^{2} + 0.4999999999999999 x + 1.0}{- 0.008333333333333339 x^{3} + 0.1 x^{2} - 0.5000000000000001 x + 1.0}$" ], "text/plain": [ "(0.00833333333333333*x**3 + 0.09999999999999997*x**2 + 0.4999999999999999*x + 1.0)/(-0.008333333333333339*x**3 + 0.1*x**2 - 0.5000000000000001*x + 1.0)" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "precision = 16\n", "pade, path = ba.pade(p, q, var, coeffs_list, precision)\n", "pade" ] }, { "cell_type": "code", "execution_count": 133, "id": "c7f214c1", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}0.001388888888888889 x^{6} + 0.008333333333333333 x^{5} + 0.04166666666666667 x^{4} + 0.1666666666666667 x^{3} + 0.5 x^{2} + 1.0 x + 1.0\\\\0.008333333333333333 x^{5} + 0.04166666666666667 x^{4} + 0.1666666666666667 x^{3} + 0.5 x^{2} + 1.0 x + 1.0\\\\\\frac{0.001388888888888889 x^{5} + 0.01388888888888889 x^{4} + 0.08333333333333333 x^{3} + 0.3333333333333333 x^{2} + 0.8333333333333333 x + 1.0}{1.0 - 0.1666666666666667 x}\\\\\\frac{0.008333333333333334 x^{4} + 0.06666666666666667 x^{3} + 0.3 x^{2} + 0.8 x + 1.0}{1.0 - 0.2 x}\\\\\\frac{0.00277777777777778 x^{4} + 0.03333333333333335 x^{3} + 0.2 x^{2} + 0.6666666666666667 x + 1.0}{0.03333333333333332 x^{2} - 0.3333333333333333 x + 1.0}\\\\\\frac{0.01666666666666667 x^{3} + 0.15 x^{2} + 0.6 x + 1.0}{0.05 x^{2} - 0.4 x + 1.0}\\\\\\frac{0.00833333333333333 x^{3} + 0.09999999999999997 x^{2} + 0.4999999999999999 x + 1.0}{- 0.008333333333333339 x^{3} + 0.1 x^{2} - 0.5000000000000001 x + 1.0}\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[ 0.001388888888888889*x**6 + 0.008333333333333333*x**5 + 0.04166666666666667*x**4 + 0.1666666666666667*x**3 + 0.5*x**2 + 1.0*x + 1.0],\n", "[ 0.008333333333333333*x**5 + 0.04166666666666667*x**4 + 0.1666666666666667*x**3 + 0.5*x**2 + 1.0*x + 1.0],\n", "[(0.001388888888888889*x**5 + 0.01388888888888889*x**4 + 0.08333333333333333*x**3 + 0.3333333333333333*x**2 + 0.8333333333333333*x + 1.0)/(1.0 - 0.1666666666666667*x)],\n", "[ (0.008333333333333334*x**4 + 0.06666666666666667*x**3 + 0.3*x**2 + 0.8*x + 1.0)/(1.0 - 0.2*x)],\n", "[ (0.00277777777777778*x**4 + 0.03333333333333335*x**3 + 0.2*x**2 + 0.6666666666666667*x + 1.0)/(0.03333333333333332*x**2 - 0.3333333333333333*x + 1.0)],\n", "[ (0.01666666666666667*x**3 + 0.15*x**2 + 0.6*x + 1.0)/(0.05*x**2 - 0.4*x + 1.0)],\n", "[ (0.00833333333333333*x**3 + 0.09999999999999997*x**2 + 0.4999999999999999*x + 1.0)/(-0.008333333333333339*x**3 + 0.1*x**2 - 0.5000000000000001*x + 1.0)]])" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "path" ] }, { "cell_type": "code", "execution_count": 134, "id": "c57c09d1", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 2.71830985915493$" ], "text/plain": [ "2.718309859154930" ] }, "execution_count": 134, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e_approx = pade.subs(var, 1.0)\n", "e_approx" ] }, { "cell_type": "code", "execution_count": 135, "id": "32a47954", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}2.718055555555556\\\\2.716666666666667\\\\2.718333333333333\\\\2.71875\\\\2.718253968253968\\\\2.717948717948718\\\\2.71830985915493\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[2.718055555555556],\n", "[2.716666666666667],\n", "[2.718333333333333],\n", "[ 2.71875],\n", "[2.718253968253968],\n", "[2.717948717948718],\n", "[ 2.71830985915493]])" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e_approx_path = path.subs(var, 1.0)\n", "e_approx_path" ] }, { "cell_type": "markdown", "id": "84102a8c", "metadata": {}, "source": [ "We will use bokeh library to plot. Use: pip install bokeh" ] }, { "cell_type": "code", "execution_count": 136, "id": "85627fdf", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " \n", " Loading BokehJS ...\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\nconst JS_MIME_TYPE = 'application/javascript';\n const HTML_MIME_TYPE = 'text/html';\n const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n const CLASS_NAME = 'output_bokeh rendered_html';\n\n /**\n * Render data to the DOM node\n */\n function render(props, node) {\n const script = document.createElement(\"script\");\n node.appendChild(script);\n }\n\n /**\n * Handle when an output is cleared or removed\n */\n function handleClearOutput(event, handle) {\n const cell = handle.cell;\n\n const id = cell.output_area._bokeh_element_id;\n const server_id = cell.output_area._bokeh_server_id;\n // Clean up Bokeh references\n if (id != null && id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n\n if (server_id !== undefined) {\n // Clean up Bokeh references\n const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n cell.notebook.kernel.execute(cmd_clean, {\n iopub: {\n output: function(msg) {\n const id = msg.content.text.trim();\n if (id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n }\n }\n });\n // Destroy server and session\n const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n cell.notebook.kernel.execute(cmd_destroy);\n }\n }\n\n /**\n * Handle when a new output is added\n */\n function handleAddOutput(event, handle) {\n const output_area = handle.output_area;\n const output = handle.output;\n\n // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n return\n }\n\n const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n\n if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n // store reference to embed id on output_area\n output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n }\n if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n const bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n const script_attrs = bk_div.children[0].attributes;\n for (let i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n }\n\n function register_renderer(events, OutputArea) {\n\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n const toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[toinsert.length - 1]);\n element.append(toinsert);\n return toinsert\n }\n\n /* Handle when an output is cleared or removed */\n events.on('clear_output.CodeCell', handleClearOutput);\n events.on('delete.Cell', handleClearOutput);\n\n /* Handle when a new output is added */\n events.on('output_added.OutputArea', handleAddOutput);\n\n /**\n * Register the mime type and append_mime function with output_area\n */\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n /* Is output safe? */\n safe: true,\n /* Index of renderer in `output_area.display_order` */\n index: 0\n });\n }\n\n // register the mime type if in Jupyter Notebook environment and previously unregistered\n if (root.Jupyter !== undefined) {\n const events = require('base/js/events');\n const OutputArea = require('notebook/js/outputarea').OutputArea;\n\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n }\n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n const NB_LOAD_WARNING = {'data': {'text/html':\n \"
\\n\"+\n \"

\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"

\\n\"+\n \"\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"
\"}};\n\n function display_loaded() {\n const el = document.getElementById(\"5376\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error(url) {\n console.error(\"failed to load \" + url);\n }\n\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\"];\n const css_urls = [];\n\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {\n }\n ];\n\n function run_inline_js() {\n if (root.Bokeh !== undefined || force === true) {\n for (let i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\nif (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n const cell = $(document.getElementById(\"5376\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));", "application/vnd.bokehjs_load.v0+json": "" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from bokeh.io import push_notebook, show, output_notebook\n", "from bokeh.plotting import figure\n", "output_notebook()" ] }, { "cell_type": "code", "execution_count": 137, "id": "523cfc8e", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle e^{x}$" ], "text/plain": [ "exp(x)" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "exp = sp.exp(var)\n", "exp" ] }, { "cell_type": "code", "execution_count": 139, "id": "71459d9c", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{x^{6}}{720} + \\frac{x^{5}}{120} + \\frac{x^{4}}{24} + \\frac{x^{3}}{6} + \\frac{x^{2}}{2} + x + 1$" ], "text/plain": [ "x**6/720 + x**5/120 + x**4/24 + x**3/6 + x**2/2 + x + 1" ] }, "execution_count": 139, "metadata": {}, "output_type": "execute_result" } ], "source": [ "maclaurin_pol = ma.polynomial(p, q, var, exp)\n", "maclaurin_pol\n" ] }, { "cell_type": "code", "execution_count": 140, "id": "c859dc66", "metadata": {}, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\frac{\\frac{x^{3}}{120} + \\frac{x^{2}}{10} + \\frac{x}{2} + 1}{- \\frac{x^{3}}{120} + \\frac{x^{2}}{10} - \\frac{x}{2} + 1}$" ], "text/plain": [ "(x**3/120 + x**2/10 + x/2 + 1)/(-x**3/120 + x**2/10 - x/2 + 1)" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pade_33 = da.pade(p, q, var, coeffs_list)\n", "pade_33" ] }, { "cell_type": "code", "execution_count": 142, "id": "dffc6075", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 149, "id": "03080c90", "metadata": {}, "outputs": [], "source": [ "x_set = np.linspace(-3,3,100) \n", "exp_y = [float(exp.subs(var, i)) for i in x_set]\n", "maclaurin_pol_y = [ float(maclaurin_pol.subs(var, i)) for i in x_set]\n", "pade_33_y = [float(pade_33.subs(var, i)) for i in x_set]" ] }, { "cell_type": "code", "execution_count": 156, "id": "916470ee", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "(function(root) {\n function embed_document(root) {\n const docs_json = {\"d08b8dfd-93d4-4d27-a1da-5fa6869468df\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"7285\"}],\"center\":[{\"id\":\"7288\"},{\"id\":\"7292\"},{\"id\":\"7324\"}],\"height\":500,\"left\":[{\"id\":\"7289\"}],\"renderers\":[{\"id\":\"7311\"},{\"id\":\"7330\"},{\"id\":\"7350\"}],\"title\":{\"id\":\"7313\"},\"toolbar\":{\"id\":\"7300\"},\"x_range\":{\"id\":\"7277\"},\"x_scale\":{\"id\":\"7281\"},\"y_range\":{\"id\":\"7279\"},\"y_scale\":{\"id\":\"7283\"}},\"id\":\"7276\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"7365\",\"type\":\"Selection\"},{\"attributes\":{\"label\":{\"value\":\"exp(x)\"},\"renderers\":[{\"id\":\"7311\"}]},\"id\":\"7325\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"7294\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"7296\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"7319\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"7277\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"7326\"},\"glyph\":{\"id\":\"7327\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"7329\"},\"nonselection_glyph\":{\"id\":\"7328\"},\"view\":{\"id\":\"7331\"}},\"id\":\"7330\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"x\":{\"__ndarray__\":\"AAAAAAAACMCEDz744IMHwAgffPDBBwfAjC666KKLBsAQPvjggw8GwJNNNtlkkwXAF1100UUXBcCbbLLJJpsEwB988MEHHwTAo4suuuiiA8Anm2yyySYDwKqqqqqqqgLALrrooosuAsCyySabbLIBwDbZZJNNNgHAuuiiiy66AMA++OCDDz4AwIQPPvjgg/+/jC666KKL/r+TTTbZZJP9v5tssskmm/y/o4suuuii+7+qqqqqqqr6v7LJJptssvm/uuiiiy66+L/CBx988MH3v8omm2yyyfa/0UUXXXTR9b/ZZJNNNtn0v+GDDz744PO/6KKLLrro8r/wwQcffPDxv/jggw8++PC/AAAAAAAA8L8QPvjggw/uvyB88MEHH+y/MLrooosu6r88+OCDDz7ov0w22WSTTea/XHTRRRdd5L9ssskmm2ziv3zwwQcffOC/GF100UUX3b842WSTTTbZv1BVVVVVVdW/cNFFF1100b8gm2yyySbLv2CTTTbZZMO/QBdddNFFt78AH3zwwQefvwAffPDBB58/QBdddNFFtz9gk0022WTDPzCbbLLJJss/eNFFF1100T9YVVVVVVXVPzjZZJNNNtk/GF100UUX3T988MEHH3zgP2yyySabbOI/YHTRRRdd5D9QNtlkk03mP0D44IMPPug/MLrooosu6j8gfPDBBx/sPxA++OCDD+4/AAAAAAAA8D/44IMPPvjwP/DBBx988PE/6KKLLrro8j/ggw8++ODzP9hkk0022fQ/0EUXXXTR9T/MJptsssn2P8QHH3zwwfc/vOiiiy66+D+0ySabbLL5P6yqqqqqqvo/pIsuuuii+z+cbLLJJpv8P5RNNtlkk/0/jC666KKL/j+EDz744IP/Pz744IMPPgBAuuiiiy66AEA22WSTTTYBQLLJJptssgFALrrooosuAkCsqqqqqqoCQCibbLLJJgNApIsuuuiiA0AgfPDBBx8EQJxssskmmwRAGF100UUXBUCUTTbZZJMFQBA++OCDDwZAjC666KKLBkAIH3zwwQcHQIQPPvjggwdAAAAAAAAACEA=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[100]},\"y\":[0.048275862068965524,0.05152384479958442,0.05495713836150925,0.05858820183110063,0.062430258787436535,0.06649734401335494,0.07080435311404282,0.07536709523957648,0.08020234910982642,0.08532792255290457,0.09076271578189973,0.09652678864906324,0.10264143213192364,0.1091292443220737,0.11601421120463992,0.12332179253477529,0.13107901313695797,0.13931455997350403,0.14805888535057016,0.1573443166530932,0.16720517302467194,0.1776778894343941,0.18880114860014358,0.20061602126705314,0.21316611537058439,0.2264977346463083,0.24066004728290705,0.2557052652513301,0.27168883498149876,0.28866964009859203,0.306710216973852,0.32587698389017206,0.3462404846705947,0.36787564766839376,0.3908620610708402,0.4152842655252123,0.4412320651553401,0.4688008581002134,0.4980919877732172,0.5292131161117272,0.5622786201624731,0.5974100134287715,0.6347363934919401,0.6743949175116483,0.7165313073094055,0.7613003858468108,0.8088666470267565,0.8594048608728665,0.9131007162817973,0.9701515036966298,1.0307668402199417,1.095169439875222,1.1635959319386862,1.2362977305045457,1.313541958720642,1.3956124314442415,1.4828107004272133,1.5754571665547614,1.6738922641430225,1.7784777228610351,1.8895979134970669,2.0076612845563444,2.1331018975785137,2.2663810701244937,2.4079891366346238,2.5584473388394664,2.7183098591549295,2.8881660125660265,3.068642614959953,3.2604065487823424,3.464167550347381,3.6806812472367407,3.9107524790978014,4.155238940946662,4.415055194973887,4.691177105055011,4.984646757941804,5.296577946768062,5.628162306426097,5.98067620702408,6.355488531592547,6.7540694881784695,7.178000635326186,7.628986334792965,8.108866887561756,8.619633660535595,9.163446573942132,9.742654396274533,10.359818388195238,11.017739953958326,11.719493104733509,12.468462720844173,13.26838983008707,14.123425411278385,15.038194605173498,16.017873694946783,17.068282841020146,18.195998369165043,19.408489484621416,20.714285714285708]},\"selected\":{\"id\":\"7365\"},\"selection_policy\":{\"id\":\"7364\"}},\"id\":\"7346\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"data\":{\"x\":{\"__ndarray__\":\"AAAAAAAACMCEDz744IMHwAgffPDBBwfAjC666KKLBsAQPvjggw8GwJNNNtlkkwXAF1100UUXBcCbbLLJJpsEwB988MEHHwTAo4suuuiiA8Anm2yyySYDwKqqqqqqqgLALrrooosuAsCyySabbLIBwDbZZJNNNgHAuuiiiy66AMA++OCDDz4AwIQPPvjgg/+/jC666KKL/r+TTTbZZJP9v5tssskmm/y/o4suuuii+7+qqqqqqqr6v7LJJptssvm/uuiiiy66+L/CBx988MH3v8omm2yyyfa/0UUXXXTR9b/ZZJNNNtn0v+GDDz744PO/6KKLLrro8r/wwQcffPDxv/jggw8++PC/AAAAAAAA8L8QPvjggw/uvyB88MEHH+y/MLrooosu6r88+OCDDz7ov0w22WSTTea/XHTRRRdd5L9ssskmm2ziv3zwwQcffOC/GF100UUX3b842WSTTTbZv1BVVVVVVdW/cNFFF1100b8gm2yyySbLv2CTTTbZZMO/QBdddNFFt78AH3zwwQefvwAffPDBB58/QBdddNFFtz9gk0022WTDPzCbbLLJJss/eNFFF1100T9YVVVVVVXVPzjZZJNNNtk/GF100UUX3T988MEHH3zgP2yyySabbOI/YHTRRRdd5D9QNtlkk03mP0D44IMPPug/MLrooosu6j8gfPDBBx/sPxA++OCDD+4/AAAAAAAA8D/44IMPPvjwP/DBBx988PE/6KKLLrro8j/ggw8++ODzP9hkk0022fQ/0EUXXXTR9T/MJptsssn2P8QHH3zwwfc/vOiiiy66+D+0ySabbLL5P6yqqqqqqvo/pIsuuuii+z+cbLLJJpv8P5RNNtlkk/0/jC666KKL/j+EDz744IP/Pz744IMPPgBAuuiiiy66AEA22WSTTTYBQLLJJptssgFALrrooosuAkCsqqqqqqoCQCibbLLJJgNApIsuuuiiA0AgfPDBBx8EQJxssskmmwRAGF100UUXBUCUTTbZZJMFQBA++OCDDwZAjC666KKLBkAIH3zwwQcHQIQPPvjggwdAAAAAAAAACEA=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[100]},\"y\":[0.049787068367863944,0.05289777828495217,0.05620284622522774,0.059714415732185264,0.0634453890813037,0.06740947468583237,0.07162123746450355,0.07609615235623413,0.08085066117844035,0.0859022330378763,0.09126942851595804,0.0969719678644051,0.1030308034617642,0.1094681967970374,0.11630780026326815,0.12357474406161391,0.13129572853520916,0.13949912227207403,0.14821506633752016,0.15747558501902606,0.1673147034904833,0.17776857282813782,0.18887560283756186,0.20067660317969205,0.21321493331446215,0.22653666181295534,0.24069073562342452,0.25572915991310063,0.2717071891465671,0.288683530102765,0.3067205575765568,0.32588454355738394,0.34624590072707134,0.36787944117144233,0.39086465125630715,0.4152859836777805,0.4412331677599839,0.4688015391402354,0.498092390053061,0.5292133415000504,0.5622787386729877,0.5974100710831303,0.6347364189402819,0.6743949274217547,0.7165313105737895,0.7613003866968739,0.8088666471820898,0.8594048608885094,0.9131007162822624,0.9701515036966302,1.030766840219941,1.095169439874664,1.1635959319175062,1.2362977302671292,1.3135419572539495,1.3956124250860897,1.4828106786375894,1.5754571033903184,1.6738921026004079,1.7784773480143699,1.8895971087303083,2.007659663086746,2.133098798766666,2.2663754066284665,2.407979174119919,2.558430384497103,2.718281828459045,2.888120835221818,3.0685714304947185,3.2602966292874,3.464000871972231,3.680432612552513,3.9103870686464144,4.154709143290675,4.414296529299399,4.690103007584092,4.983141951553612,5.2944900504700305,5.625291265440799,5.976761032582408,6.3501907287988875,6.7469524165833965,7.168503885276326,7.616394007302631,8.092268429068351,8.597875617425943,9.135073283924447,9.705835210448594,10.312258501325772,10.95657128854658,11.641140918409853,12.368482649671398,13.141268895155592,13.962339040785407,14.834709878108175,15.761586688648478,16.746375020814504,17.792693202628776,18.904385636257807,20.085536923187668]},\"selected\":{\"id\":\"7322\"},\"selection_policy\":{\"id\":\"7321\"}},\"id\":\"7307\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"7320\",\"type\":\"AllLabels\"},{\"attributes\":{\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7308\",\"type\":\"Line\"},{\"attributes\":{\"label\":{\"value\":\"maclaurin(x)\"},\"renderers\":[{\"id\":\"7330\"}]},\"id\":\"7345\",\"type\":\"LegendItem\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"7313\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"7342\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"7307\"}},\"id\":\"7312\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"7298\",\"type\":\"HelpTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"7299\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"tools\":[{\"id\":\"7293\"},{\"id\":\"7294\"},{\"id\":\"7295\"},{\"id\":\"7296\"},{\"id\":\"7297\"},{\"id\":\"7298\"}]},\"id\":\"7300\",\"type\":\"Toolbar\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"7307\"},\"glyph\":{\"id\":\"7308\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"7310\"},\"nonselection_glyph\":{\"id\":\"7309\"},\"view\":{\"id\":\"7312\"}},\"id\":\"7311\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"7293\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"7364\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"7325\"},{\"id\":\"7345\"},{\"id\":\"7367\"}]},\"id\":\"7324\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"7286\",\"type\":\"BasicTicker\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"7319\"},\"group\":null,\"major_label_policy\":{\"id\":\"7320\"},\"ticker\":{\"id\":\"7286\"}},\"id\":\"7285\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_alpha\":0.2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7310\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"green\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7348\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"7290\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"7283\",\"type\":\"LinearScale\"},{\"attributes\":{\"line_color\":\"green\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7347\",\"type\":\"Line\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"7316\"},\"group\":null,\"major_label_policy\":{\"id\":\"7317\"},\"ticker\":{\"id\":\"7290\"}},\"id\":\"7289\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_alpha\":0.1,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7309\",\"type\":\"Line\"},{\"attributes\":{\"overlay\":{\"id\":\"7299\"}},\"id\":\"7295\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"7321\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"7316\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"label\":{\"value\":\"[3/3](x)\"},\"renderers\":[{\"id\":\"7350\"}]},\"id\":\"7367\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"7281\",\"type\":\"LinearScale\"},{\"attributes\":{\"source\":{\"id\":\"7326\"}},\"id\":\"7331\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"7279\",\"type\":\"DataRange1d\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"green\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7349\",\"type\":\"Line\"},{\"attributes\":{\"data\":{\"x\":{\"__ndarray__\":\"AAAAAAAACMCEDz744IMHwAgffPDBBwfAjC666KKLBsAQPvjggw8GwJNNNtlkkwXAF1100UUXBcCbbLLJJpsEwB988MEHHwTAo4suuuiiA8Anm2yyySYDwKqqqqqqqgLALrrooosuAsCyySabbLIBwDbZZJNNNgHAuuiiiy66AMA++OCDDz4AwIQPPvjgg/+/jC666KKL/r+TTTbZZJP9v5tssskmm/y/o4suuuii+7+qqqqqqqr6v7LJJptssvm/uuiiiy66+L/CBx988MH3v8omm2yyyfa/0UUXXXTR9b/ZZJNNNtn0v+GDDz744PO/6KKLLrro8r/wwQcffPDxv/jggw8++PC/AAAAAAAA8L8QPvjggw/uvyB88MEHH+y/MLrooosu6r88+OCDDz7ov0w22WSTTea/XHTRRRdd5L9ssskmm2ziv3zwwQcffOC/GF100UUX3b842WSTTTbZv1BVVVVVVdW/cNFFF1100b8gm2yyySbLv2CTTTbZZMO/QBdddNFFt78AH3zwwQefvwAffPDBB58/QBdddNFFtz9gk0022WTDPzCbbLLJJss/eNFFF1100T9YVVVVVVXVPzjZZJNNNtk/GF100UUX3T988MEHH3zgP2yyySabbOI/YHTRRRdd5D9QNtlkk03mP0D44IMPPug/MLrooosu6j8gfPDBBx/sPxA++OCDD+4/AAAAAAAA8D/44IMPPvjwP/DBBx988PE/6KKLLrro8j/ggw8++ODzP9hkk0022fQ/0EUXXXTR9T/MJptsssn2P8QHH3zwwfc/vOiiiy66+D+0ySabbLL5P6yqqqqqqvo/pIsuuuii+z+cbLLJJpv8P5RNNtlkk/0/jC666KKL/j+EDz744IP/Pz744IMPPgBAuuiiiy66AEA22WSTTTYBQLLJJptssgFALrrooosuAkCsqqqqqqoCQCibbLLJJgNApIsuuuiiA0AgfPDBBx8EQJxssskmmwRAGF100UUXBUCUTTbZZJMFQBA++OCDDwZAjC666KKLBkAIH3zwwQcHQIQPPvjggwdAAAAAAAAACEA=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[100]},\"y\":[0.36250000000000004,0.3255585010187647,0.2932415542172765,0.2651525225806818,0.24092533482833112,0.22022297395545276,0.20273601533086083,0.188181214350651,0.17630014364792118,0.16685787985849765,0.1596417399426725,0.15446006706294757,0.15114106601779742,0.149531688231432,0.149496566299577,0.15091699809126288,0.1536899804066213,0.1577272921906968,0.16295462730326532,0.16931077684466284,0.17674686103762652,0.18522561066514534,0.19472069806431958,0.20521611767623252,0.21670561615183193,0.22919217201382155,0.24268752487456305,0.2572117542099878,0.27279290768951997,0.28946667906201007,0.3072761355976767,0.3262714950860613,0.3465099523899914,0.3680555555555556,0.3909791314780869,0.41535826112415863,0.441277304309589,0.46882747403345704,0.49810696036812746,0.5292211039052879,0.562282618757995,0.5974118651187305,0.6347371713734697,0.6743952057717575,0.716531397652797,0.7613004082275465,0.808866650916829,0.8594048612454507,0.9131007162923295,0.9701515036966348,1.0307668402199361,1.0951694398643654,1.1635959315467845,1.2362977263289674,1.31354193420379,1.3956123304374337,1.482810371467594,1.575456260357705,1.6738900618071688,1.778472866717602,1.889588006315084,2.007642315828423,2.133067447723428,2.2663212344931956,2.407889101004401,2.558285526399602,2.7180555555555554,2.887776360097545,3.0680588489697094,3.2595493285613952,3.4629312123895097,3.678926780336886,3.9082989874466634,4.1518533222726735,4.410439714785827,4.684954493836542,4.976342394173147,5.28559861301631,5.613770916189484,5.961961793805349,6.331330665508275,6.723096135272791,7.138538295758064,7.579001082218393,8.045894675969697,8.540697957412048,9.064961008608172,9.620307665417986,10.208438119189154,10.831131568003599,11.490248917480125,12.187735531132942,12.925624030286262,13.70603714354491,14.531190605820898,15.40339610691606,16.325064289660677,17.2987077976081,18.32694437228539,19.412499999999998]},\"selected\":{\"id\":\"7343\"},\"selection_policy\":{\"id\":\"7342\"}},\"id\":\"7326\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"7317\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"7297\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"7343\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"7285\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"7288\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"7346\"}},\"id\":\"7351\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"7289\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"7292\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"7322\",\"type\":\"Selection\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7329\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7328\",\"type\":\"Line\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"7346\"},\"glyph\":{\"id\":\"7347\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"7349\"},\"nonselection_glyph\":{\"id\":\"7348\"},\"view\":{\"id\":\"7351\"}},\"id\":\"7350\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"7327\",\"type\":\"Line\"}],\"root_ids\":[\"7276\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.3\"}};\n const render_items = [{\"docid\":\"d08b8dfd-93d4-4d27-a1da-5fa6869468df\",\"root_ids\":[\"7276\"],\"roots\":{\"7276\":\"8bc1709d-148b-4703-8158-a690f45c30b3\"}}];\n root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n }\n if (root.Bokeh !== undefined) {\n embed_document(root);\n } else {\n let attempts = 0;\n const timer = setInterval(function(root) {\n if (root.Bokeh !== undefined) {\n clearInterval(timer);\n embed_document(root);\n } else {\n attempts++;\n if (attempts > 100) {\n clearInterval(timer);\n console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n }\n }\n }, 10, root)\n }\n})(window);", "application/vnd.bokehjs_exec.v0+json": "" }, "metadata": { "application/vnd.bokehjs_exec.v0+json": { "id": "7276" } }, "output_type": "display_data" } ], "source": [ "p = figure(plot_width = 600, plot_height = 500)\n", "p.line(x_set, exp_y, color = 'black', legend_label= 'exp(x)')\n", "p.line(x_set, maclaurin_pol_y, color = 'red', legend_label= 'maclaurin(x)')\n", "p.line(x_set, pade_33_y, color = 'green', legend_label='[3/3](x)')\n", "show(p)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.5 ('py_Ven')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.5" }, "vscode": { "interpreter": { "hash": "3921ad618ee8e8ca721fc489c8b7fb57942a7e45f25682ec6d5afa5e61832ade" } } }, "nbformat": 4, "nbformat_minor": 5 }