{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# 1-Dimensional Interpolation\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import ndsplines\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import interpolate\nfrom scipy.stats import norm\nimport itertools\n\n\ndef gaussian(x_in):\n    z = norm.ppf(.9995)\n    x = z*(2*x_in-1)\n    return norm.pdf(x)\n\ndef sin(x_in):\n    x = np.pi*(x_in-0.5)\n    return np.sin(x)\n\ndef tanh(x_in):\n    x = 2*np.pi*(x_in-0.5)\n    return np.tanh(x)\n\nfuncs = [gaussian, sin, tanh]\n\nx = np.linspace(0, 1, 9)\nxx = np.linspace(-.25, 1.25, 1024)\nk = 3\n\nfor degree in range(0,4):\n    for func in funcs:\n        fvals = func(x)\n        truef = func(xx)\n        plt.figure()\n    \n        plot_sel = slice(None)\n    \n        plt.gca().set_prop_cycle(None)\n        test_Bspline = interpolate.make_interp_spline(x, fvals, k=degree)\n        splinef = test_Bspline(xx.copy(), extrapolate=True)\n        plt.plot(xx, splinef, '--', lw=3.0, label='scipy.interpolate.make_interp_spline')\n\n        test_NDBspline = ndsplines.make_interp_spline(x, fvals, degrees=degree)\n        NDsplinef = test_NDBspline(xx.copy())\n        plt.plot(xx, NDsplinef, label='ndspline.make_interp_spline')\n        \n        plt.plot(xx, truef, 'k--', label=\"True \" + func.__name__)\n        plt.plot(x, fvals, 'ko')\n        plt.title('k=%d'%degree)\n        \n        plt.legend(loc='best')\n        plt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}