# -*- coding: utf-8 -*-
"""
Created on Wed Aug 10 17:14:06 2022

@author: Chris
Lab 3 Q2
"""

import numpy as np
import matplotlib.pyplot as plt

def f(x):
    f = x*np.cos(x)+x*np.sin(x/2)
    #f = x*np.sin(x**2)+x**2
    return f

def minbracket(f,a,b,N):
    blist = []
    h = (b-a)/N
    for i in range(1,N):
        
        xa = a+(i-1)*h
        xb = a+i*h
        xc = a+(i+1)*h
        
        if f(xb)<f(xa) and f(xb)<f(xc):
            #print('Minimum found between',xa,'and',xc)
            blist.append([xa,xb])
    return blist  
    
x = np.linspace(-5,5,1000)
plt.plot(x,f(x))

a = -5      #leftmost point in search
b = 5       #rightmost point in search
N = 20      # number of intervals

blist = minbracket(f,a,b,N)

print(*blist)

     
    
    
