

### (a): Graphically show that the function is unimodal on the interval [0,3]. (You may use software to create the graph.)


```python
import numpy as np
import pandas as pd
```


```python
#generate a list of x values with end points 0 and 3
start = 0
stop = 3
x_values = np.linspace(start, stop, num = 50, endpoint = True, retstep = False,   dtype = float)

x_list, f_x = [], [] #create lists to store data
for value in x_values:
    temp = (0.5/np.sqrt(1+value**2))-(np.sqrt(1+value**2)*(1-(0.5/(1+value**2))))+value
    x_list.append(value)
    f_x.append(temp)

fx_max_value = max(f_x) #Return the max value of the list.
fx_max_index = f_x. index(fx_max_value) #return index of max value
x_at_max_value = x_list[fx_max_index] #get x value corresponding to fx_max
```


```python
fx_max_value, x_at_max_value
```




    (0.3002635410437066, 0.7959183673469388)




```python
# importing the required module
import matplotlib.pyplot as plt
 
plt.figure(figsize=(8, 4))
plt.plot(x_list, f_x)
plt.axvline(x = x_at_max_value, ymin = min(f_x), ymax=0.95, linestyle = ":", color="firebrick", label="Maximizer")
plt.xlabel('x', fontsize = 18)
plt.ylabel('f(x)', fontsize = 18)
plt.xticks(fontsize = 16)
plt.yticks(fontsize = 16)
plt.legend(loc="center", fontsize = 16)
plt.title('Grapgh of f(x)', fontsize = 20)
plt.show()
```

A function is unimodal on an interval if it has a single minimizer or single maximizer on that interval, and not both. The displayed graph has only one maximizer

### (b) Use the bisection method to find a MAXIMUM for this function with a tolerance of 10^(-5)

The bisection method is part of family of elimination methods which are numerical methods for nonlinear optimization (single variable). In this method, the size of the region containing the optimal solution is reduced in each round of iteration.

__1.__ The bisection method assumes that the function f(x) to be minimized is continuously differentiable in the given closed interval [a, b]

__2.__ $\Delta$f(a)$\Delta$f(b)<0

**Steps:**

1. Let C = 0.5(a+b). If b-c > 


```python
import sympy as sympy
import math
```


```python
def logistic_funtcion(x):
    return 1/(1 + sympy.exp(-x)) 

def differential():
    x = sympy.symbols('x') 
    f_x = logistic_funtcion(x)
    return f_x.diff(x)

f_x_prime = differential()
print(f_x_prime)
```

    exp(-x)/(1 + exp(-x))**2


#### Bisection method


```python
def bisection(fx, fxprime,a,b,Threshold):
    """
    proximate solution of f(x)=0 on interval [a,b] by bisection method.

    Parameters
    ----------
    fx : Function 
        The function to be maximized
    fxprime: differential of the function to be maximized
    a,b : Numbers
        The interval to search for a solution. 
    Threshold: float
        The threshold of approximation error to terminate iteration
    @eturns
    -------
    df:
       pandas dataframe of a,b, midpoint values, function evalauted at each iteration, slope of function at each iteration
    """
    
    #create list to store data
    a_list, b_list, c_list, diff_list, fprime_b_list, fprime_c_list, mult_list, fx_c_list= [],[],[],[],[],[],[],[]
    
    #calculate midpoint
    c = (a + b)/2
    
    #calculate difference
    diff = b-c
    
    #if the difference is smaller or equal to threshold, return
    if diff <= Threshold:
        return c
    
    #find optimal point by iteration
    while diff >Threshold:
        fprime_b = fxprime(a) #evaluate differential at lower limit
        fprime_c = fxprime(b) #evaluate differential at upperit
        mult = fprime_b*fprime_c
        
        #evaluate function at current optimal
        fx_c = fx(c)
        a_list.append(a), b_list.append(b), c_list.append(c), diff_list.append(diff)
        
        fprime_b_list.append(fprime_b), fprime_c_list.append(fprime_c), mult_list.append(mult), fx_c_list.append(fx_c)
        
        if mult <=0:
            a = c
        else:
            b = c
        
        #recalculate the medpoint
        c = (a + b)/2
        
        #recalculate the diff
        diff = b-c
    
    #save data in a pandas dataframe
    df = pd.DataFrame(zip(a_list, b_list, c_list, diff_list, fprime_b_list, fprime_c_list, mult_list, fx_c_list),
                     columns = ["a", "b", "c", "b-c", "f'(b)", "f'(c)", "f'(b)*f'(c)", "f(c)"]
                     )
    return df
```


```python
def class_example(x):
    return x**5 - 5*x**3 - 20*x + 5

def differential():
    x = sympy.symbols('x') 
    f_x = class_example(x)
    return f_x.diff(x)

examp_prime = differential()
examp_prime
```




$\displaystyle 5 x^{4} - 15 x^{2} - 20$




```python
fx = lambda x: x**5 - 5*x**3 - 20*x + 5
#differential of function
fxprime = lambda x: 5*x**4 - 15*x**2 - 20
x_optimal = bisection(fx,fxprime, 0,3,0.00001)
```


```python
x_optimal
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>c</th>
      <th>b-c</th>
      <th>f'(b)</th>
      <th>f'(c)</th>
      <th>f'(b)*f'(c)</th>
      <th>f(c)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.00</td>
      <td>3.000000</td>
      <td>1.500000</td>
      <td>1.500000</td>
      <td>-20.000000</td>
      <td>250.000000</td>
      <td>-5000.000000</td>
      <td>-34.281250</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1.50</td>
      <td>3.000000</td>
      <td>2.250000</td>
      <td>0.750000</td>
      <td>-28.437500</td>
      <td>250.000000</td>
      <td>-7109.375000</td>
      <td>-39.288086</td>
    </tr>
    <tr>
      <th>2</th>
      <td>2.25</td>
      <td>3.000000</td>
      <td>2.625000</td>
      <td>0.375000</td>
      <td>32.207031</td>
      <td>250.000000</td>
      <td>8051.757812</td>
      <td>-13.302582</td>
    </tr>
    <tr>
      <th>3</th>
      <td>2.25</td>
      <td>2.625000</td>
      <td>2.437500</td>
      <td>0.187500</td>
      <td>32.207031</td>
      <td>114.044189</td>
      <td>3673.024774</td>
      <td>-30.116387</td>
    </tr>
    <tr>
      <th>4</th>
      <td>2.25</td>
      <td>2.437500</td>
      <td>2.343750</td>
      <td>0.093750</td>
      <td>32.207031</td>
      <td>67.380447</td>
      <td>2170.124175</td>
      <td>-35.525708</td>
    </tr>
    <tr>
      <th>5</th>
      <td>2.25</td>
      <td>2.343750</td>
      <td>2.296875</td>
      <td>0.046875</td>
      <td>32.207031</td>
      <td>48.476796</td>
      <td>1561.293689</td>
      <td>-37.597503</td>
    </tr>
    <tr>
      <th>6</th>
      <td>2.25</td>
      <td>2.296875</td>
      <td>2.273438</td>
      <td>0.023438</td>
      <td>32.207031</td>
      <td>40.027089</td>
      <td>1289.153720</td>
      <td>-38.488612</td>
    </tr>
    <tr>
      <th>7</th>
      <td>2.25</td>
      <td>2.273438</td>
      <td>2.261719</td>
      <td>0.011719</td>
      <td>32.207031</td>
      <td>36.040124</td>
      <td>1160.745400</td>
      <td>-38.899578</td>
    </tr>
    <tr>
      <th>8</th>
      <td>2.25</td>
      <td>2.261719</td>
      <td>2.255859</td>
      <td>0.005859</td>
      <td>32.207031</td>
      <td>34.104563</td>
      <td>1098.406720</td>
      <td>-39.096612</td>
    </tr>
    <tr>
      <th>9</th>
      <td>2.25</td>
      <td>2.255859</td>
      <td>2.252930</td>
      <td>0.002930</td>
      <td>32.207031</td>
      <td>33.151071</td>
      <td>1067.697567</td>
      <td>-39.193040</td>
    </tr>
    <tr>
      <th>10</th>
      <td>2.25</td>
      <td>2.252930</td>
      <td>2.251465</td>
      <td>0.001465</td>
      <td>32.207031</td>
      <td>32.677873</td>
      <td>1052.457268</td>
      <td>-39.240736</td>
    </tr>
    <tr>
      <th>11</th>
      <td>2.25</td>
      <td>2.251465</td>
      <td>2.250732</td>
      <td>0.000732</td>
      <td>32.207031</td>
      <td>32.442158</td>
      <td>1044.865592</td>
      <td>-39.264454</td>
    </tr>
    <tr>
      <th>12</th>
      <td>2.25</td>
      <td>2.250732</td>
      <td>2.250366</td>
      <td>0.000366</td>
      <td>32.207031</td>
      <td>32.324521</td>
      <td>1041.076860</td>
      <td>-39.276281</td>
    </tr>
    <tr>
      <th>13</th>
      <td>2.25</td>
      <td>2.250366</td>
      <td>2.250183</td>
      <td>0.000183</td>
      <td>32.207031</td>
      <td>32.265758</td>
      <td>1039.184270</td>
      <td>-39.282186</td>
    </tr>
    <tr>
      <th>14</th>
      <td>2.25</td>
      <td>2.250183</td>
      <td>2.250092</td>
      <td>0.000092</td>
      <td>32.207031</td>
      <td>32.236390</td>
      <td>1038.238418</td>
      <td>-39.285137</td>
    </tr>
    <tr>
      <th>15</th>
      <td>2.25</td>
      <td>2.250092</td>
      <td>2.250046</td>
      <td>0.000046</td>
      <td>32.207031</td>
      <td>32.221709</td>
      <td>1037.765603</td>
      <td>-39.286611</td>
    </tr>
    <tr>
      <th>16</th>
      <td>2.25</td>
      <td>2.250046</td>
      <td>2.250023</td>
      <td>0.000023</td>
      <td>32.207031</td>
      <td>32.214370</td>
      <td>1037.529223</td>
      <td>-39.287349</td>
    </tr>
    <tr>
      <th>17</th>
      <td>2.25</td>
      <td>2.250023</td>
      <td>2.250011</td>
      <td>0.000011</td>
      <td>32.207031</td>
      <td>32.210701</td>
      <td>1037.411040</td>
      <td>-39.287717</td>
    </tr>
  </tbody>
</table>
</div>




```python
def function(x):
    return (0.5*((1 + x**2)**-0.5))-(((1+ x**2)**0.5)*(1-(0.5*(1 + x**2)**-1))) + x

def differential():
    x = sympy.symbols('x') 
    f_x = function(x)
    return f_x.diff(x)

f_x_prime = differential()
f_x_prime
```




$\displaystyle - \frac{1.0 x \left(1 - \frac{0.5}{x^{2} + 1}\right)}{\left(x^{2} + 1\right)^{0.5}} - \frac{1.5 x}{\left(x^{2} + 1\right)^{1.5}} + 1$




```python
#function to optimize
fx = lambda x: (0.5*((1 + x**2)**-0.5))-(((1+ x**2)**0.5)*(1-(0.5*(1 + x**2)**-1))) + x

#differential of function
fxprime = lambda x: (-x*(1 - 0.5/(1+x**2))/(1+x**2)**0.5) - (1.5*x/(x**2+1)**1.5) + 1
#fxprime = lambda x: 1 - x*((1+x**2)**-1.5+(1+x**2)**-0.5)

x_optimal = bisection(fx,fxprime, 0,3,0.00001)
```


```python
x_optimal
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>c</th>
      <th>b-c</th>
      <th>f'(b)</th>
      <th>f'(c)</th>
      <th>f'(b)*f'(c)</th>
      <th>f(c)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.0</td>
      <td>3.000000</td>
      <td>1.500000</td>
      <td>1.500000</td>
      <td>1.000000</td>
      <td>-0.043552</td>
      <td>-0.043552</td>
      <td>0.251925</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1.5</td>
      <td>3.000000</td>
      <td>2.250000</td>
      <td>0.750000</td>
      <td>-0.088066</td>
      <td>-0.043552</td>
      <td>0.003835</td>
      <td>0.193924</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.5</td>
      <td>2.250000</td>
      <td>1.875000</td>
      <td>0.375000</td>
      <td>-0.088066</td>
      <td>-0.064543</td>
      <td>0.005684</td>
      <td>0.220588</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.5</td>
      <td>1.875000</td>
      <td>1.687500</td>
      <td>0.187500</td>
      <td>-0.088066</td>
      <td>-0.077753</td>
      <td>0.006847</td>
      <td>0.235758</td>
    </tr>
    <tr>
      <th>4</th>
      <td>1.5</td>
      <td>1.687500</td>
      <td>1.593750</td>
      <td>0.093750</td>
      <td>-0.088066</td>
      <td>-0.083880</td>
      <td>0.007387</td>
      <td>0.243742</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.5</td>
      <td>1.593750</td>
      <td>1.546875</td>
      <td>0.046875</td>
      <td>-0.088066</td>
      <td>-0.086345</td>
      <td>0.007604</td>
      <td>0.247813</td>
    </tr>
    <tr>
      <th>6</th>
      <td>1.5</td>
      <td>1.546875</td>
      <td>1.523438</td>
      <td>0.023438</td>
      <td>-0.088066</td>
      <td>-0.087320</td>
      <td>0.007690</td>
      <td>0.249864</td>
    </tr>
    <tr>
      <th>7</th>
      <td>1.5</td>
      <td>1.523438</td>
      <td>1.511719</td>
      <td>0.011719</td>
      <td>-0.088066</td>
      <td>-0.087724</td>
      <td>0.007726</td>
      <td>0.250893</td>
    </tr>
    <tr>
      <th>8</th>
      <td>1.5</td>
      <td>1.511719</td>
      <td>1.505859</td>
      <td>0.005859</td>
      <td>-0.088066</td>
      <td>-0.087903</td>
      <td>0.007741</td>
      <td>0.251409</td>
    </tr>
    <tr>
      <th>9</th>
      <td>1.5</td>
      <td>1.505859</td>
      <td>1.502930</td>
      <td>0.002930</td>
      <td>-0.088066</td>
      <td>-0.087987</td>
      <td>0.007749</td>
      <td>0.251667</td>
    </tr>
    <tr>
      <th>10</th>
      <td>1.5</td>
      <td>1.502930</td>
      <td>1.501465</td>
      <td>0.001465</td>
      <td>-0.088066</td>
      <td>-0.088027</td>
      <td>0.007752</td>
      <td>0.251796</td>
    </tr>
    <tr>
      <th>11</th>
      <td>1.5</td>
      <td>1.501465</td>
      <td>1.500732</td>
      <td>0.000732</td>
      <td>-0.088066</td>
      <td>-0.088046</td>
      <td>0.007754</td>
      <td>0.251860</td>
    </tr>
    <tr>
      <th>12</th>
      <td>1.5</td>
      <td>1.500732</td>
      <td>1.500366</td>
      <td>0.000366</td>
      <td>-0.088066</td>
      <td>-0.088056</td>
      <td>0.007755</td>
      <td>0.251892</td>
    </tr>
    <tr>
      <th>13</th>
      <td>1.5</td>
      <td>1.500366</td>
      <td>1.500183</td>
      <td>0.000183</td>
      <td>-0.088066</td>
      <td>-0.088061</td>
      <td>0.007755</td>
      <td>0.251908</td>
    </tr>
    <tr>
      <th>14</th>
      <td>1.5</td>
      <td>1.500183</td>
      <td>1.500092</td>
      <td>0.000092</td>
      <td>-0.088066</td>
      <td>-0.088063</td>
      <td>0.007755</td>
      <td>0.251916</td>
    </tr>
    <tr>
      <th>15</th>
      <td>1.5</td>
      <td>1.500092</td>
      <td>1.500046</td>
      <td>0.000046</td>
      <td>-0.088066</td>
      <td>-0.088065</td>
      <td>0.007755</td>
      <td>0.251921</td>
    </tr>
    <tr>
      <th>16</th>
      <td>1.5</td>
      <td>1.500046</td>
      <td>1.500023</td>
      <td>0.000023</td>
      <td>-0.088066</td>
      <td>-0.088065</td>
      <td>0.007756</td>
      <td>0.251923</td>
    </tr>
    <tr>
      <th>17</th>
      <td>1.5</td>
      <td>1.500023</td>
      <td>1.500011</td>
      <td>0.000011</td>
      <td>-0.088066</td>
      <td>-0.088065</td>
      <td>0.007756</td>
      <td>0.251924</td>
    </tr>
  </tbody>
</table>
</div>



### Golden section search method


```python
def golden_section_search_method(fx,a,b,Threshold):
    """
    proximate solution of f(x)=0 on interval [a,b] by bisection method.

    Parameters
    ----------
    fx : Function 
        The function to be maximized
    a,b : Numbers
        The interval to search for a solution. 
    Threshold: float
        The threshold of approximation error to terminate iteration
    @eturns
    -------
    df:
       pandas dataframe of a,b, midpoint values, function evalauted at each iteration, slope of function at each iteration
    """
    
    #create list to store data
    a_list, b_list, diff_list, x1_list, x2_list, fx_x1_list, fx_x2_list= [],[],[],[],[],[],[]
    
    #Golden ration
    gamma = (-1+ math.sqrt(5))/2
    #calculate difference
    diff = b-a
    
    #if the difference is smaller or equal to threshold, return
    if diff <= Threshold:
        if fx(a) < fx(b):
            return a #minimizer
        else:
            return b #as minimizer
    
    #find optimal point by iteration
    while diff >Threshold:
        x1 = b - gamma*(b-a)
        x2 = a + gamma*(b-a)        
        fx_x1 = fx(x1) #evaluate differential at lower limit
        fx_x2 = fx(x2) #evaluate differential at upperit
        
        a_list.append(a), b_list.append(b), diff_list.append(diff)
        
        x1_list.append(x1), x2_list.append(x2), fx_x1_list.append(fx_x1), fx_x2_list.append(fx_x2)

        if fx_x1 < fx_x2:
            b = x2
        else:
            a = x1
            #if the difference is smaller or equal to threshold, return
        if diff <= Threshold:
            if fx(a) < fx(b):
                return a #minimizer
            else:
                return b #as minimizer
        
        diff = b-a
    #save data in a pandas dataframe
    df = pd.DataFrame(zip(a_list, b_list, diff_list, x1_list, x2_list, fx_x1_list, fx_x2_list),
                     columns = ["a", "b", "b-a", "x1", "x2", "f(x1)", "f(x2)"])
    return df
```


```python
#function to optimize
fx = lambda x: (0.5*((1 + x**2)**-0.5))-(((1+ x**2)**0.5)*(1-(0.5*(1 + x**2)**-1))) + x
x_optimal = golden_section_search_method(fx,0,3,0.00001)
x_optimal
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>b-a</th>
      <th>x1</th>
      <th>x2</th>
      <th>f(x1)</th>
      <th>f(x2)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.000000</td>
      <td>3</td>
      <td>3.000000</td>
      <td>1.145898</td>
      <td>1.854102</td>
      <td>0.282529</td>
      <td>0.222221</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1.145898</td>
      <td>3</td>
      <td>1.854102</td>
      <td>1.854102</td>
      <td>2.291796</td>
      <td>0.222221</td>
      <td>0.191256</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.854102</td>
      <td>3</td>
      <td>1.145898</td>
      <td>2.291796</td>
      <td>2.562306</td>
      <td>0.191256</td>
      <td>0.175343</td>
    </tr>
    <tr>
      <th>3</th>
      <td>2.291796</td>
      <td>3</td>
      <td>0.708204</td>
      <td>2.562306</td>
      <td>2.729490</td>
      <td>0.175343</td>
      <td>0.166590</td>
    </tr>
    <tr>
      <th>4</th>
      <td>2.562306</td>
      <td>3</td>
      <td>0.437694</td>
      <td>2.729490</td>
      <td>2.832816</td>
      <td>0.166590</td>
      <td>0.161552</td>
    </tr>
    <tr>
      <th>5</th>
      <td>2.729490</td>
      <td>3</td>
      <td>0.270510</td>
      <td>2.832816</td>
      <td>2.896674</td>
      <td>0.161552</td>
      <td>0.158571</td>
    </tr>
    <tr>
      <th>6</th>
      <td>2.832816</td>
      <td>3</td>
      <td>0.167184</td>
      <td>2.896674</td>
      <td>2.936141</td>
      <td>0.158571</td>
      <td>0.156777</td>
    </tr>
    <tr>
      <th>7</th>
      <td>2.896674</td>
      <td>3</td>
      <td>0.103326</td>
      <td>2.936141</td>
      <td>2.960533</td>
      <td>0.156777</td>
      <td>0.155686</td>
    </tr>
    <tr>
      <th>8</th>
      <td>2.936141</td>
      <td>3</td>
      <td>0.063859</td>
      <td>2.960533</td>
      <td>2.975608</td>
      <td>0.155686</td>
      <td>0.155019</td>
    </tr>
    <tr>
      <th>9</th>
      <td>2.960533</td>
      <td>3</td>
      <td>0.039467</td>
      <td>2.975608</td>
      <td>2.984925</td>
      <td>0.155019</td>
      <td>0.154609</td>
    </tr>
    <tr>
      <th>10</th>
      <td>2.975608</td>
      <td>3</td>
      <td>0.024392</td>
      <td>2.984925</td>
      <td>2.990683</td>
      <td>0.154609</td>
      <td>0.154357</td>
    </tr>
    <tr>
      <th>11</th>
      <td>2.984925</td>
      <td>3</td>
      <td>0.015075</td>
      <td>2.990683</td>
      <td>2.994242</td>
      <td>0.154357</td>
      <td>0.154201</td>
    </tr>
    <tr>
      <th>12</th>
      <td>2.990683</td>
      <td>3</td>
      <td>0.009317</td>
      <td>2.994242</td>
      <td>2.996441</td>
      <td>0.154201</td>
      <td>0.154105</td>
    </tr>
    <tr>
      <th>13</th>
      <td>2.994242</td>
      <td>3</td>
      <td>0.005758</td>
      <td>2.996441</td>
      <td>2.997801</td>
      <td>0.154105</td>
      <td>0.154046</td>
    </tr>
    <tr>
      <th>14</th>
      <td>2.996441</td>
      <td>3</td>
      <td>0.003559</td>
      <td>2.997801</td>
      <td>2.998641</td>
      <td>0.154046</td>
      <td>0.154009</td>
    </tr>
    <tr>
      <th>15</th>
      <td>2.997801</td>
      <td>3</td>
      <td>0.002199</td>
      <td>2.998641</td>
      <td>2.999160</td>
      <td>0.154009</td>
      <td>0.153987</td>
    </tr>
    <tr>
      <th>16</th>
      <td>2.998641</td>
      <td>3</td>
      <td>0.001359</td>
      <td>2.999160</td>
      <td>2.999481</td>
      <td>0.153987</td>
      <td>0.153973</td>
    </tr>
    <tr>
      <th>17</th>
      <td>2.999160</td>
      <td>3</td>
      <td>0.000840</td>
      <td>2.999481</td>
      <td>2.999679</td>
      <td>0.153973</td>
      <td>0.153964</td>
    </tr>
    <tr>
      <th>18</th>
      <td>2.999481</td>
      <td>3</td>
      <td>0.000519</td>
      <td>2.999679</td>
      <td>2.999802</td>
      <td>0.153964</td>
      <td>0.153959</td>
    </tr>
    <tr>
      <th>19</th>
      <td>2.999679</td>
      <td>3</td>
      <td>0.000321</td>
      <td>2.999802</td>
      <td>2.999877</td>
      <td>0.153959</td>
      <td>0.153955</td>
    </tr>
    <tr>
      <th>20</th>
      <td>2.999802</td>
      <td>3</td>
      <td>0.000198</td>
      <td>2.999877</td>
      <td>2.999924</td>
      <td>0.153955</td>
      <td>0.153953</td>
    </tr>
    <tr>
      <th>21</th>
      <td>2.999877</td>
      <td>3</td>
      <td>0.000123</td>
      <td>2.999924</td>
      <td>2.999953</td>
      <td>0.153953</td>
      <td>0.153952</td>
    </tr>
    <tr>
      <th>22</th>
      <td>2.999924</td>
      <td>3</td>
      <td>0.000076</td>
      <td>2.999953</td>
      <td>2.999971</td>
      <td>0.153952</td>
      <td>0.153951</td>
    </tr>
    <tr>
      <th>23</th>
      <td>2.999953</td>
      <td>3</td>
      <td>0.000047</td>
      <td>2.999971</td>
      <td>2.999982</td>
      <td>0.153951</td>
      <td>0.153951</td>
    </tr>
    <tr>
      <th>24</th>
      <td>2.999971</td>
      <td>3</td>
      <td>0.000029</td>
      <td>2.999982</td>
      <td>2.999989</td>
      <td>0.153951</td>
      <td>0.153951</td>
    </tr>
    <tr>
      <th>25</th>
      <td>2.999982</td>
      <td>3</td>
      <td>0.000018</td>
      <td>2.999989</td>
      <td>2.999993</td>
      <td>0.153951</td>
      <td>0.153950</td>
    </tr>
    <tr>
      <th>26</th>
      <td>2.999989</td>
      <td>3</td>
      <td>0.000011</td>
      <td>2.999993</td>
      <td>2.999996</td>
      <td>0.153950</td>
      <td>0.153950</td>
    </tr>
  </tbody>
</table>
</div>




```python
#class example
fx = lambda x: x**5 - 5*x**3 - 20*x + 5
x_optimal = golden_section_search_method(fx,0,3,0.00001)
x_optimal
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>b-a</th>
      <th>x1</th>
      <th>x2</th>
      <th>f(x1)</th>
      <th>f(x2)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.000000</td>
      <td>3.000000</td>
      <td>3.000000</td>
      <td>1.145898</td>
      <td>1.854102</td>
      <td>-23.465512</td>
      <td>-42.039920</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1.145898</td>
      <td>3.000000</td>
      <td>1.854102</td>
      <td>1.854102</td>
      <td>2.291796</td>
      <td>-42.039920</td>
      <td>-37.798567</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1.145898</td>
      <td>2.291796</td>
      <td>1.145898</td>
      <td>1.583592</td>
      <td>1.854102</td>
      <td>-36.569198</td>
      <td>-42.039920</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1.583592</td>
      <td>2.291796</td>
      <td>0.708204</td>
      <td>1.854102</td>
      <td>2.021286</td>
      <td>-42.039920</td>
      <td>-42.977005</td>
    </tr>
    <tr>
      <th>4</th>
      <td>1.854102</td>
      <td>2.291796</td>
      <td>0.437694</td>
      <td>2.021286</td>
      <td>2.124612</td>
      <td>-42.977005</td>
      <td>-42.153429</td>
    </tr>
    <tr>
      <th>5</th>
      <td>1.854102</td>
      <td>2.124612</td>
      <td>0.270510</td>
      <td>1.957428</td>
      <td>2.021286</td>
      <td>-42.912047</td>
      <td>-42.977005</td>
    </tr>
    <tr>
      <th>6</th>
      <td>1.957428</td>
      <td>2.124612</td>
      <td>0.167184</td>
      <td>2.021286</td>
      <td>2.060753</td>
      <td>-42.977005</td>
      <td>-42.807468</td>
    </tr>
    <tr>
      <th>7</th>
      <td>1.957428</td>
      <td>2.060753</td>
      <td>0.103326</td>
      <td>1.996894</td>
      <td>2.021286</td>
      <td>-42.999519</td>
      <td>-42.977005</td>
    </tr>
    <tr>
      <th>8</th>
      <td>1.957428</td>
      <td>2.021286</td>
      <td>0.063859</td>
      <td>1.981819</td>
      <td>1.996894</td>
      <td>-42.983682</td>
      <td>-42.999519</td>
    </tr>
    <tr>
      <th>9</th>
      <td>1.981819</td>
      <td>2.021286</td>
      <td>0.039467</td>
      <td>1.996894</td>
      <td>2.006211</td>
      <td>-42.999519</td>
      <td>-42.998063</td>
    </tr>
    <tr>
      <th>10</th>
      <td>1.981819</td>
      <td>2.006211</td>
      <td>0.024392</td>
      <td>1.991136</td>
      <td>1.996894</td>
      <td>-42.996096</td>
      <td>-42.999519</td>
    </tr>
    <tr>
      <th>11</th>
      <td>1.991136</td>
      <td>2.006211</td>
      <td>0.015075</td>
      <td>1.996894</td>
      <td>2.000453</td>
      <td>-42.999519</td>
      <td>-42.999990</td>
    </tr>
    <tr>
      <th>12</th>
      <td>1.996894</td>
      <td>2.006211</td>
      <td>0.009317</td>
      <td>2.000453</td>
      <td>2.002653</td>
      <td>-42.999990</td>
      <td>-42.999648</td>
    </tr>
    <tr>
      <th>13</th>
      <td>1.996894</td>
      <td>2.002653</td>
      <td>0.005758</td>
      <td>1.999094</td>
      <td>2.000453</td>
      <td>-42.999959</td>
      <td>-42.999990</td>
    </tr>
    <tr>
      <th>14</th>
      <td>1.999094</td>
      <td>2.002653</td>
      <td>0.003559</td>
      <td>2.000453</td>
      <td>2.001293</td>
      <td>-42.999990</td>
      <td>-42.999916</td>
    </tr>
    <tr>
      <th>15</th>
      <td>1.999094</td>
      <td>2.001293</td>
      <td>0.002199</td>
      <td>1.999934</td>
      <td>2.000453</td>
      <td>-43.000000</td>
      <td>-42.999990</td>
    </tr>
    <tr>
      <th>16</th>
      <td>1.999094</td>
      <td>2.000453</td>
      <td>0.001359</td>
      <td>1.999613</td>
      <td>1.999934</td>
      <td>-42.999993</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>17</th>
      <td>1.999613</td>
      <td>2.000453</td>
      <td>0.000840</td>
      <td>1.999934</td>
      <td>2.000132</td>
      <td>-43.000000</td>
      <td>-42.999999</td>
    </tr>
    <tr>
      <th>18</th>
      <td>1.999613</td>
      <td>2.000132</td>
      <td>0.000519</td>
      <td>1.999811</td>
      <td>1.999934</td>
      <td>-42.999998</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>19</th>
      <td>1.999811</td>
      <td>2.000132</td>
      <td>0.000321</td>
      <td>1.999934</td>
      <td>2.000010</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>20</th>
      <td>1.999934</td>
      <td>2.000132</td>
      <td>0.000198</td>
      <td>2.000010</td>
      <td>2.000056</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>21</th>
      <td>1.999934</td>
      <td>2.000056</td>
      <td>0.000123</td>
      <td>1.999981</td>
      <td>2.000010</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>22</th>
      <td>1.999981</td>
      <td>2.000056</td>
      <td>0.000076</td>
      <td>2.000010</td>
      <td>2.000028</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>23</th>
      <td>1.999981</td>
      <td>2.000028</td>
      <td>0.000047</td>
      <td>1.999999</td>
      <td>2.000010</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>24</th>
      <td>1.999981</td>
      <td>2.000010</td>
      <td>0.000029</td>
      <td>1.999992</td>
      <td>1.999999</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>25</th>
      <td>1.999992</td>
      <td>2.000010</td>
      <td>0.000018</td>
      <td>1.999999</td>
      <td>2.000003</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
    <tr>
      <th>26</th>
      <td>1.999992</td>
      <td>2.000003</td>
      <td>0.000011</td>
      <td>1.999996</td>
      <td>1.999999</td>
      <td>-43.000000</td>
      <td>-43.000000</td>
    </tr>
  </tbody>
</table>
</div>




```python

```


```python

```

3c90eb9a117230ea86077d40b5272b2f3f21df2e
ipynb
Jupyter Notebook
bisection_and_golden_section_search_methods.ipynb
VillageDeveloper2019/Optimization
799cb44513b7bbac272bf90803d0f5ccf440281a
MIT
bisection_and_golden_section_search_methods.ipynb
VillageDeveloper2019/Optimization
799cb44513b7bbac272bf90803d0f5ccf440281a
MIT
bisection_and_golden_section_search_methods.ipynb
VillageDeveloper2019/Optimization
799cb44513b7bbac272bf90803d0f5ccf440281a
MIT
Qwen/Qwen-72B
1. YES
2. YES