Function doesn't show result

Jul
Wed, 22 Apr 2020 14:15:32 +0000
New to Julia

Hello! I wrote little function but its not show output. I am fresh in this language and I’ve no idea why it’s not work.
My input is : f(x->1) after that program freezes.
This is function:

function f(func=x^2)
a_lower = 1
b_upper = 2
ro = (3 - sqrt(5))/2
eps = b_upper - a_lower

a_old = a_lower
b_old = b_upper
iter = 0
while(eps > 10^-5)

    a_new = a_old + (b_old - a_old)*ro
    b_new = b_old - (b_old - a_old)*ro

    if (func(b_new) > func(a_new))
        b_old = b_new
    elseif (func(b_new) < func(a_new))
        a_old = a_new
    end
    eps = b_old - a_old
    iter = iter + 1

end

print(a_new,func(a_new))

4 posts - 4 participants