{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bisection method"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We first import the modules and functions that we need."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'svg'\n",
"from numpy import exp,sin,linspace,sign,abs\n",
"from matplotlib.pyplot import plot,grid,xlabel,ylabel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First we define the function for which the root is required."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"def fun(x):\n",
" #f = x**2 - 4*x*sin(x) + (2*sin(x))**2\n",
" f = exp(x) - sin(x)\n",
" return f"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let us plot and visualize the function."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"