Skip to content

Instantly share code, notes, and snippets.

@vaibkumr
Created January 6, 2020 20:56
Show Gist options
  • Save vaibkumr/8e37399d4740928a258f395413bde2e7 to your computer and use it in GitHub Desktop.
Save vaibkumr/8e37399d4740928a258f395413bde2e7 to your computer and use it in GitHub Desktop.
Fixed point problem
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step1: Imports"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import warnings\n",
"warnings.simplefilter(\"ignore\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step2: Define f and plot it to make sure it's converging"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" return np.sin(x)/x\n",
"\n",
"def plot(lower=-1, upper=200):\n",
" ys, xs = [], []\n",
" plt.figure(figsize=(6, 4))\n",
" for x in range(lower, upper):\n",
" try:\n",
" ys.append(f(x))\n",
" xs.append(x)\n",
" except:\n",
" continue\n",
" plt.xlabel(\"x\") \n",
" plt.ylabel(\"f(x)\") \n",
" plt.plot(xs, ys)\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAEKCAYAAADuEgmxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzt3Xd8W+W9x/HPT8N27DiOncSZTuxMEhIycAYEKBQoe1ygEFoKtEB6KbS0dFx66W25lJbSQbm0tKxSRtkU2lBSVtiEDCcheznTzrATMuwM7+f+cSRFtiVbtLEUku/79fIL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Bb8KrIyXaCc24ccBZwg5mdFP2g8+rEKRmWZ97Fu84Hng9tOhSOVzOpPD7xmNmtQAPwZGjTFqC/c24scDPwlHlX0kyWQ+59a+Fymv8wSfrxinFuiOjIz5hCo7lNQEHU/X6hbSlhZkG8D8WTzrkXAZxzFc65RuddL/0hOqhq3hbn3KbQfyvxrq44AagIV3mtjUv4JsFZwHznXEWojCk/XiHxjk/KP3NmdjVwLvDl0MmGUPPPJ6Hb8/D6DoYmq0xtvG+HwvEKABcBz4a3Jft4xTo3kKTPmEKjubnAEDMrCv1inYJ3adqkC7WZ/glY7py7O2p7dFvkfwBLWv6/HVyuLDPLDt/G60hdQgKX8E2SZr8AU328osQ7PtOAK0MjXCYBu6OaGDqcmZ0J/AA43zm3L2p7DzPzh24PBIYAa5NYrnjv2zRgipmlm1lRqFxzklWukNOAFc658vCGZB6veOcGkvUZS0Zv/2fpD2+kwSq8Xwq3prAcJ+BVLxcBH4f+zgaeABaHtk8Deie5XAPxRq8sBJaGjxHQDZgBrAbeBPJScMyygE+AnKhtST9eeKG1BajHaz++Jt7xwRvRcl/o87YYKE5yuUrx2rvDn7H7Q/teHHp/PwbmA+cluVxx3zfg1tDxWgmclcxyhbY/Cvxni32TebzinRuS8hnTjHAREUmYmqdERCRhCg0REUmYQkNERBKm0BARkYQpNEREJGEKDRERSZhCQ0REEqbQEOlgZjY+tPBeRmhG/VIzG5nqcon8KzS5TyQJzOwOIAPoBJQ75+5McZFE/iUKDZEkCK1lNheoAY53zjWmuEgi/xI1T4kkRzegM96V1jJSXBaRf5lqGiJJYGbT8K4EWYS3+N6NKS6SyL8kkOoCiBzuzOxKoN4591Ro+eyZZvZ559xbqS6byKelmoaIiCRMfRoiIpIwhYaIiCRMoSEiIglTaIiISMIUGiIikjCFhoiIJEyhISIiCVNoiIhIwv4fHxSFkZTCckoAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The function above is clearly converging"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Step 3: Solve the fixed point problem by repeatedly applying the function infinite times\n",
"\n",
"Note: Instead of infinity, we just apply it `10000` times"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def fixed_point(INF = 10000):\n",
" x0 = np.random.randn()\n",
" for _ in range(INF):\n",
" x0 = f(x0)\n",
" return x0 "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.8767262153950625\n"
]
}
],
"source": [
"solution = fixed_point()\n",
"print(solution)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def verify(solution):\n",
" print(f\"Values of function: f{f(solution)} | Value of x: {solution}\")\n",
" if f(solution) == solution:\n",
" return True"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Values of function: f0.8767262153950625 | Value of x: 0.8767262153950625\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"verify(solution)"
]
}
],
"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": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment