{"id":130,"date":"2019-01-03T16:14:58","date_gmt":"2019-01-04T00:14:58","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=130"},"modified":"2019-01-03T16:14:58","modified_gmt":"2019-01-04T00:14:58","slug":"spline-interpolation-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/spline-interpolation-2\/","title":{"rendered":"Spline interpolation"},"content":{"rendered":"<pre>import os\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy import interpolate\nos.chdir(r'D:\\data\\scripts\\web1\\ex26')\nos.getcwd()\ndef runge(x):\n    return 1\/(1 + 25 * x**2)\n\nx = np.linspace(-1, 1, 11)\ny = runge(x)\nf = interpolate.interp1d(x, y, kind=3)\nxx = np.linspace(-1, 1, 100)\nfig, ax = plt.subplots(figsize=(8, 4))\nax.plot(xx, runge(xx), 'k', lw=1, label=\"Runge's function\")\nax.plot(x, y, 'ro', label='sample points')\nax.plot(xx, f(xx), 'r--', lw=2, label='spline order 3')\nax.legend()\nax.set_ylim(0, 1.1)\nax.set_xticks([-1, -0.5, 0, 0.5, 1])\nax.set_ylabel(r\"$y$\", fontsize=18)\nax.set_xlabel(r\"$x$\", fontsize=18)\nfig.tight_layout()\nax.set_title(\"Spline Interpolation\")\nfig.tight_layout()\nplt.savefig(\"example26.png\", dpi=100)\nplt.show()\nplt.close()\n\n<img data-recalc-dims=\"1\" decoding=\"async\" class=\"  wp-image-131 aligncenter\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example26.png?resize=626%2C313\" alt=\"example26\" width=\"626\" height=\"313\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example26.png?w=800&amp;ssl=1 800w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example26.png?resize=300%2C150&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example26.png?resize=768%2C384&amp;ssl=1 768w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import os import matplotlib.pyplot as plt import numpy as np from scipy import interpolate os.chdir(r&#8217;D:\\data\\scripts\\web1\\ex26&#8242;) 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), &#8216;k&#8217;, lw=1, label=&#8221;Runge&#8217;s function&#8221;) ax.plot(x, y, [&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-130","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-26","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":127,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/runge-problem\/","url_meta":{"origin":130,"position":0},"title":"Runge problem","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\\ex25') os.getcwd() # In the mathematical field of numerical analysis, Runge's phenomenon # is a problem of oscillation at the edges of an interval that occurs # when using polynomial interpolation with polynomials of\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example25","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example25.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example25.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example25.png?resize=525%2C300 1.5x"},"classes":[]},{"id":133,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/spline-interpolation-3\/","url_meta":{"origin":130,"position":1},"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":121,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/polynomial-interpolation\/","url_meta":{"origin":130,"position":2},"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":130,"position":3},"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":157,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/numerical-integration-of-odes-using-scipy\/","url_meta":{"origin":130,"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":154,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/inexact-solutions-to-odes\/","url_meta":{"origin":130,"position":5},"title":"Inexact solutions to ODEs","author":"gantovnik","date":"2019-01-08","format":false,"excerpt":"\u00a0 import os import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import sympy from IPython.display import display sympy.init_printing() mpl.rcParams['text.usetex'] = True import sympy os.chdir(r'D:\\projects\\wordpress\\ex33') 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\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example33","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/130","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=130"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}