from math import exp

def f(x):
    return 1 + (-4 * x**2 - 10 * x + 8) * exp(-0.5 * x)

a, b = -4, -2
k = 1
while b - a > 10**(-k):
    m = (a + b) / 2
    p = f(a) * f(m)
    print(a, b, m, p, b - a)
    if p > 0:
        a = m
    else:
        b = m
        

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: