findroot expects function, not equation

try
sage: find_root(erseno(x),2,10,xtol=0.01)

does this work?

Robert

On 9 ún, 15:54, Giovanni Lanzani <ulisses...@gmail.com> wrote:
> "ma...@mendelu.cz" <ma...@mendelu.cz> writes:
> > On 9 ún, 11:22, Giovanni Lanzani <ulisses...@gmail.com> wrote:
> >> Dear all
>
> >> I have the following sage code
>
> >> sage: 
> >> gamma,r,gangle,dz2,Nstep,Nrib,b=var('gamma,r,gangle,dz2,Nstep,Nrib,b')
> >> sage: a=11.5; b=6;#this is fixed
> >> sage: Nstep=2;Nrib=5;Diam=33;gangle=30*2*3.1415/360;gamma=40*0.33+20*0.33;
> >> sage: #these have all to be changed when using different structure
> >> sage: r=(Diam-2*a)/2;th=2*3.1415*Nstep/Nrib;
> >> sage: def theta(dz):
> >> ...       return 2*arcsin(dz*tan(gangle)/2/r);
> >> ...
> >> sage: def dz2(dz):
> >> ...       return (-(Nrib+1)/(Nrib-1)*dz+b*cos(gangle)*2/(Nrib-1));
> >> sage: def erseno(x):
> >> ...       return 
> >> 2*arcsin(b*sin(gangle)/2/r)-(Nrib-1)*theta(dz2(x))/2-(Nrib+1)*theta(x)/2;
> >> sage: find_root(erseno(x)==0,2,gamma,xtol=0.01)
> >> 0.0
>
> > You look for the zero on the interval which is not subset of the
> > domain of the function.  Try erseno(gamma) ....
> > Do not know why Sage returns result which is not true, but you can try
> > this:
>
> > sage:
> > gamma,r,gangle,dz2,Nstep,Nrib,b=var('gamma,r,gangle,dz2,Nstep,Nrib,b')
> > sage: a=11.5; b=6;#this is fixed
> > sage:
> > Nstep=2;Nrib=5;Diam=33;gangle=30*2*3.1415/360;gamma=40*0.33+20*0.33;
> > sage: r=(Diam-2*a)/2;th=2*3.1415*Nstep/Nrib;
> > sage: def theta(dz):
> > ....:     return 2*arcsin(dz*tan(gangle)/2/r);
> > ....:
> > sage: def dz2(dz):
> > ....:     return (-(Nrib+1)/(Nrib-1)*dz+b*cos(gangle)*2/(Nrib-1));
> > ....:
> > sage: def erseno(x):
> > ....:     return 2*arcsin(b*sin(gangle)/2/r)-(Nrib-1)*theta(dz2(x))/2-
> > (Nrib+1)*theta(x)/2;
> > ....:
> > sage: erseno(gamma)
> > NaN
> > sage: find_root(erseno(x),2,10,xtol=0.01)
> > 5.1961985254756655
>
> You are right, but this then brings me to the next problem. If I define
> theta(dz) to be
>
> sage: def theta(dz):
> ...       angle=0;
> ...       if 0<=dz<2*r*cot(gangle) : angle= 2*arcsin(dz*tan(gangle)/2/r);
> ...       if 2*r*cot(gangle)<= dz < 2*2*r*cot(gangle) : angle= 
> 2*arcsin((dz-2*r*cot(gangle))/(cot(gangle)*2*r)) - pi;
> ...       if 2*2*r*cot(gangle)<= dz < 4*2*r*cot(gangle) : angle= 
> 2*arcsin((dz-2*2*r*cot(gangle))/(cot(gangle)*2*r)) - 2*pi;
> ...       if 0>=dz>-2*r*cot(gangle) : angle= 2*arcsin(dz*tan(gangle)/2/r);
> ...       if 2*r*cot(gangle)>= dz > -2*2*r*cot(gangle) : angle= 
> 2*arcsin((dz+2*r*cot(gangle))/(cot(gangle)*2*r)) - pi;
> ...       if 2*2*r*cot(gangle)>= dz > -4*2*r*cot(gangle) : angle= 
> 2*arcsin((dz+2*2*r*cot(gangle))/(cot(gangle)*2*r)) - 2*pi;
> ...       return angle;
> ...
>
> then executing
>
> sage: find_root(erseno(x)==0,2,10,xtol=0.01)
>
> I get
>
> }} Traceback (most recent call last):
> }}  File "<stdin>", line 1, in <module>
> }}  File "_sage_input_69.py", line 4, in <module>
> }}    open("___code___.py","w").write("# -*- coding: utf-8 -*-\n" + 
> _support_.preparse_worksheet_cell(base64.b64decode("ZmluZF9yb290KGVyc2Vubyh4KT09MCwyLDEwLHh0b2w9MC4wMSk="),globals())+"\n");
>  execfile(os.path.abspath("___code___.py"))
> }}  File "", line 1, in <module>
> }}    
> }}  File 
> "/private/var/folders/bc/bcpFbanYErusTUkLXieJfE+++TI/-Tmp-/tmpPx3xK6/___code___.py",
>  line 3, in <module>
> }}    find_root(erseno(x)==_sage_const_0 ,_sage_const_2 ,_sage_const_10 
> ,xtol=_sage_const_0p01 )
> }}  File "", line 1, in <module>
> }}    
> }}  File 
> "/Applications/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.py",
>  line 73, in find_root
> }}    left = f(a)
> }}TypeError: 'bool' object is not callable
> }}
>
> Thanks again for your kindness,
>
> Giovanni Lanzani

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to