While trying to solve a slightly complicated equation numerically with "find_root()" i observed the following strange behaviour. I tried to simplify it a bit, here is an example which provokes the same error:
z1=i
z2=16/13*I+128/13
m=1267/256
r=5/256*sqrt(66833)
func = lambda x: 2*arcsinh(abs(z1-m+r*cos(x)+r*z1*sin(x))/(2*sqrt(imag(z1)*imag(m+r*cos(x)+r*z1*sin(x)))))-2.5
print N(func(1))
print N(func(2))
print find_root(func,1,2)
-0.244460406765698
0.474755141742558
Traceback (most recent call last):
File "", line 1, in <module>
File "/tmp/tmpBd1BxG/___code___.py", line 12, in <module>
exec compile(u'print find_root(func,_sage_const_1 ,_sage_const_2 )
File "", line 1, in <module>
File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 113, in find_root
full_output=full_output, xtol=xtol, rtol=rtol, maxiter=maxiter)
File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/scipy/optimize/zeros.py", line 364, in brentq
r = _zeros._brentq(f,a,b,xtol,maxiter,args,full_output,disp)
ValueError: f(a) and f(b) must have different signs
obviousely func has different signs at the boundary and there is a zero of func nevertheless some function seems to complain.
A possible solution seems to be to for numeric evaluation of the function func by returning N(....). After this change everything works fine:
z1=i
z2=16/13*I+128/13
m=1267/256
r=5/256*sqrt(66833)
func = lambda x: N(2*arcsinh(abs(z1-m+r*cos(x)+r*z1*sin(x))/(2*sqrt(imag(z1)*imag(m+r*cos(x)+r*z1*sin(x)))))-2.5)
print N(func(1))
print N(func(2))
print find_root(func,1,2)
-0.244460406765698
0.474755141742558
1.36680148306
Is this problem thus related to the fact that sage tries to calculate func exactly? Shouldn't find_root as a numerical function work automatically with numerical values?
I tested everything with sage 5.0.1 on Kubuntu and sage 5.4 on the sagenb server.
Best regards,
Tobias