{"id":127,"date":"2019-01-03T16:08:32","date_gmt":"2019-01-04T00:08:32","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=127"},"modified":"2019-01-03T16:08:32","modified_gmt":"2019-01-04T00:08:32","slug":"runge-problem","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/runge-problem\/","title":{"rendered":"Runge problem"},"content":{"rendered":"<pre>import os\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom numpy import polynomial as P\nos.chdir(r'D:\\data\\scripts\\web1\\ex25')\nos.getcwd()\n# In the mathematical field of numerical analysis, Runge's phenomenon\n# is a problem of oscillation at the edges of an interval that occurs\n# when using polynomial interpolation with polynomials of high degree\n# over a set of equispaced interpolation points.\ndef runge(x):\n    return 1\/(1 + 25 * x**2)\n\ndef runge_interpolate(n):\n    x = np.linspace(-1, 1, n+1)\n    p = P.Polynomial.fit(x, runge(x), deg=n)\n    return x, p\n\nxx = np.linspace(-1, 1, 250)\nfig, ax = plt.subplots(1, 1, figsize=(8, 4))\nax.plot(xx, runge(xx), 'k', lw=2, label=\"Runge's function\")\nn = 13\nx, p = runge_interpolate(n)\nax.plot(x, runge(x), 'ro')\nax.plot(xx, p(xx), 'r', label='interp. order %d' % n)\nn = 14\nx, p = runge_interpolate(n)\nax.plot(x, runge(x), 'go')\nax.plot(xx, p(xx), 'g', label='interp. order %d' % n)\nax.legend(loc=8)\nax.set_xlim(-1.1, 1.1)\nax.set_ylim(-1, 2)\nax.set_xticks([-1, -0.5, 0, 0.5, 1])\nax.set_ylabel(r\"$y$\", fontsize=18)\nax.set_xlabel(r\"$x$\", fontsize=18)\nax.set_title(\"Runge problem\")\nfig.tight_layout()\nplt.savefig(\"example25.png\", dpi=100)\nplt.show()\nplt.close()\n\n<img data-recalc-dims=\"1\" decoding=\"async\" class=\"  wp-image-128 aligncenter\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example25.png?resize=604%2C302\" alt=\"example25\" width=\"604\" height=\"302\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example25.png?w=800&amp;ssl=1 800w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example25.png?resize=300%2C150&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example25.png?resize=768%2C384&amp;ssl=1 768w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import os import matplotlib.pyplot as plt import numpy as np from numpy import polynomial as P os.chdir(r&#8217;D:\\data\\scripts\\web1\\ex25&#8242;) os.getcwd() # In the mathematical field of numerical analysis, Runge&#8217;s phenomenon # is a problem of oscillation at the edges of an interval that occurs # when using polynomial interpolation with polynomials of high degree # over a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":null,"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-23","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":130,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/spline-interpolation-2\/","url_meta":{"origin":127,"position":0},"title":"Spline interpolation","author":"gantovnik","date":"2019-01-03","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy import interpolate os.chdir(r'D:\\data\\scripts\\web1\\ex26') os.getcwd() def runge(x): return 1\/(1 + 25 * x**2) x = np.linspace(-1, 1, 11) y = runge(x) f = interpolate.interp1d(x, y, kind=3) xx = np.linspace(-1, 1, 100) fig, ax = plt.subplots(figsize=(8, 4)) ax.plot(xx, runge(xx), 'k',\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example26","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example26.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example26.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example26.png?resize=525%2C300 1.5x"},"classes":[]},{"id":121,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/polynomial-interpolation\/","url_meta":{"origin":127,"position":1},"title":"Polynomial interpolation","author":"gantovnik","date":"2019-01-03","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from numpy import polynomial as P from scipy import linalg os.chdir(r'D:\\data\\scripts\\web1\\ex23') os.getcwd() x = np.array([1, 2, 3, 4]) y = np.array([1, 3, 5, 4]) deg = len(x) - 1 A = P.polynomial.polyvander(x, deg) c = linalg.solve(A, y) f1 = P.Polynomial(c)\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example23","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example23.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example23.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example23.png?resize=525%2C300 1.5x"},"classes":[]},{"id":124,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/polynomial-fit\/","url_meta":{"origin":127,"position":2},"title":"Polynomial fit","author":"gantovnik","date":"2019-01-03","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from numpy import polynomial as P os.chdir(r'D:\\data\\scripts\\web1\\ex24') os.getcwd() x = np.array([1, 2, 3, 4]) y = np.array([1, 3, 5, 4]) f1 = P.Polynomial.fit(x, y, 1) f2 = P.Polynomial.fit(x, y, 2) f3 = P.Polynomial.fit(x, y, 3) xx = np.linspace(x.min(), x.max(), 100)\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example24","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example24.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example24.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example24.png?resize=525%2C300 1.5x"},"classes":[]},{"id":133,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/spline-interpolation-3\/","url_meta":{"origin":127,"position":3},"title":"#27 Spline interpolation","author":"gantovnik","date":"2019-01-03","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy import interpolate os.chdir(r'D:\\data\\scripts\\web1\\ex27') os.getcwd() x = np.array([0, 1, 2, 3, 4, 5, 6, 7]) y = np.array([3, 4, 3.5, 2, 1, 1.5, 1.25, 0.9]) xx = np.linspace(x.min(), x.max(), 100) fig, ax = plt.subplots(figsize=(8, 4)) ax.scatter(x, y) for n\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example27","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example27.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example27.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example27.png?resize=525%2C300 1.5x"},"classes":[]},{"id":157,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/numerical-integration-of-odes-using-scipy\/","url_meta":{"origin":127,"position":4},"title":"Numerical integration of ODEs using SciPy","author":"gantovnik","date":"2019-01-09","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate import sympy os.chdir(r'D:\\projects\\wordpress\\ex35') os.getcwd() def plot_direction_field(x, y_x, f_xy, x_lim=(-5, 5), y_lim=(-5, 5), ax=None): f_np = sympy.lambdify((x, y_x), f_xy, 'numpy') x_vec = np.linspace(x_lim[0], x_lim[1], 20) y_vec = np.linspace(y_lim[0], y_lim[1], 20) if ax is None: _, ax =\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example35","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example35.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":88,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/linear-least-square-fit\/","url_meta":{"origin":127,"position":5},"title":"#14 Linear least square fit using python","author":"gantovnik","date":"2018-12-31","format":false,"excerpt":"","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"example13","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}