{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "# Table of Contents\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Solving an equation, numerically or with the Lambert W function\n", "\n", "I want to solve the equation $\\exp(-ax^2)=x$ and find its solution(s) as a function of $a\\in\\mathbb{R}$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading packages and configuring plot sizes" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Lilian Besson (Naereen) 2018-01-31T14:56:14+01:00\n", "\n", "CPython 3.6.3\n", "IPython 6.2.1\n", "\n", "numpy 1.14.0\n", "matplotlib 2.1.2\n", "scipy 1.0.0\n", "seaborn 0.8.1\n" ] } ], "source": [ "%load_ext watermark\n", "%watermark -a \"Lilian Besson (Naereen)\" -i -v -p numpy,matplotlib,scipy,seaborn" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import optimize as opt\n", "import matplotlib as mpl\n", "mpl.rcParams['figure.figsize'] = (15, 8)\n", "import matplotlib.pyplot as plt\n", "\n", "import seaborn as sns\n", "sns.set(context=\"notebook\", style=\"darkgrid\", palette=\"hls\", font=\"sans-serif\", font_scale=1.8)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting the function first" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def objective(x, a):\n", " return np.exp(- a * x**2) - x" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, let's have a look to its plot for some values of $a$:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[