def fct(x):
    return x * (1.5 - x)
c = (-1 + 5**0.5) / 2
a, b = 0, 1 
x1, x2 = c * a + (1 - c) * b, (1 - c) * a + c * b
fx1, fx2 = fct(x1), fct(x2)

for i in range(28):
    if fx1 > fx2: # "<" insread of ">" if minimum search
        b = x2;
        x2 = x1
        fx2 = fx1;
        x1 = c * a + (1 - c) * b
        fx1 = fct(x1)
    else:
        a = x1;
        x1 = x2;
        fx1 = fx2;
        x2 = (1 - c) * a + c * b
        fx2 = fct(x2);

print((1 - c) * a + c * b)

Embed on website

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