{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# One Variable Equations"
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_id": "00000-2303c462-3a38-4984-a18b-ad0743709cb9",
"colab_type": "text",
"deepnote_cell_type": "markdown",
"id": "cx_2LAjUw7VH",
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
"source": [
"Throughout this section and the next ones we shall cover the topic of solutions to one variable equations. Many different problems in physics and astronomy require the use of complex expressions, even with implicit dependence of variables. When it is necessary to solve for one of those variable, an analytical approach is not usually the best solution, because of its complexity or even because it does not exist at all. Different approaches for dealing with this comprehend series expansions and numerical solutions. Among the most widely used numerical approaches are the Bisection or Binary-search method, fixed-point iteration, Newton's methods.\n",
"\n",
"For further details see for example Chap. 5 of Ref. ([1](../index.ipynb#Bibliography)) or Chap. 4 of Ref. ([3](../index.ipynb#Bibliography))\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_id": "00001-9b5c5089-cfa0-452e-9212-f426a9b2eab6",
"colab_type": "text",
"deepnote_cell_type": "markdown",
"id": "sExxbMPEw7VM",
"tags": []
},
"source": [
"- - -\n",
"```{contents}\n",
":depth: 2\n",
"```\n",
"- - -"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bibliography"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[1] [Kiusalaas, Numerical Methods in Engineering with Python](https://drive.google.com/file/d/0BxoOXsn2EUNIQUdFVkctR2xWRUk/view?usp=sharing)
\n",
"[2] [Jensen, Computational_Physics](https://drive.google.com/file/d/0BxoOXsn2EUNIekRUMFVPYXVsSTg/view?usp=sharing). Companion repos: https://github.com/mhjensen [Web page](http://compphysics.github.io/ComputationalPhysics/doc/web/course)
\n",
"[3] E. Ayres, [Computational Physics With Python](http://bit.ly/CPwPython)
"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"cell_id": "00002-49209fff-523b-4f09-a260-8afe344a3a8f",
"colab": {},
"colab_type": "code",
"deepnote_cell_type": "code",
"id": "GD4z2RTZw7VN",
"outputId": "2780c361-b150-411f-b8ac-88567710c34f",
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The text.latex.preview rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The mathtext.fallback_to_cm rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: Support for setting the 'mathtext.fallback_to_cm' rcParam is deprecated since 3.3 and will be removed two minor releases later; use 'mathtext.fallback : 'cm' instead.\n",
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The validate_bool_maybe_none function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The savefig.jpeg_quality rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The keymap.all_axes rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The animation.avconv_path rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n",
"In /home/usuario/.local/lib/python3.6/site-packages/matplotlib/mpl-data/stylelib/_classic_test.mplstyle: \n",
"The animation.avconv_args rcparam was deprecated in Matplotlib 3.3 and will be removed two minor releases later.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"%pylab inline\n",
"rc('animation', html='jshtml')"
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_id": "00003-8734dc8e-26e8-48ae-b4bf-33ecdf4eff54",
"colab_type": "text",
"deepnote_cell_type": "markdown",
"id": "FY0-QkUnw7VS"
},
"source": [
"JSAnimation import available at https://github.com/jakevdp/JSAnimation"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"cell_id": "00004-e90f9125-dcd9-4194-bce3-7cce10378e9a",
"colab": {},
"colab_type": "code",
"deepnote_cell_type": "code",
"id": "5rHmuj6mw7VT"
},
"outputs": [],
"source": [
"#from JSAnimation import IPython_display\n",
"from matplotlib import animation"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"cell_id": "00005-0a61ac2b-4f46-44ea-8318-57348dcc3944",
"colab": {},
"colab_type": "code",
"deepnote_cell_type": "code",
"id": "zM--Q1_nw7VX"
},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy import integrate\n",
"from scipy import optimize"
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_id": "00006-3bad2fa9-b3cf-46d5-9042-1f7768cc9854",
"colab_type": "text",
"deepnote_cell_type": "markdown",
"id": "RNEo8n--w7Vc",
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
"source": [
"## Bisection Method"
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_id": "00007-840214c8-76fc-4a9e-ae73-d63aa27a597e",
"colab_type": "text",
"deepnote_cell_type": "markdown",
"id": "2ZgAUxxyw7Vf"
},
"source": [
"The Bisection method exploits the [intermediate value theorem](http://en.wikipedia.org/wiki/Intermediate_value_theorem), where a continuous and differentiable function $f$ must have a zero between an interval $[a,b]$ such that $f(a)f(b)<0$, or equivalently, there must be a value $p\\in[a,b]$ such that $f(p)=0$. Below the algorithmm is stated explicitly."
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_id": "00008-c9bd9d87-c169-4d2d-95f0-9cea2e1f4b1d",
"colab_type": "text",
"deepnote_cell_type": "markdown",
"id": "tCrKSgUrw7Vh",
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Steps BM"
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_id": "00009-4c1446e1-f7d5-4e2d-918a-a6e3520086d1",
"colab_type": "text",
"deepnote_cell_type": "markdown",
"id": "8uRIVSQOw7Vj"
},
"source": [
"