On 02/09/2010 04:10 PM, Giovanni Lanzani wrote:
"[email protected]"<[email protected]>  writes:


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)

Try to print erseno(x)
it seems that your equation becomes 0.609368485026990==0

It probably does because I put angle=0 at the beginning of theta(dz). If
I take it away I get (if calling erseno(x))

->Traceback (most recent call last):
->   File "<stdin>", line 1, in<module>
->   File "_sage_input_16.py", line 4, in<module>
->     open("___code___.py","w").write("# -*- coding: utf-8 -*-\n" + 
_support_.preparse_worksheet_cell(base64.b64decode("ZmluZF9yb290KGVyc2Vubyh4KSwyLDEwLHh0b2w9MC4wMSk="),globals())+"\n"); 
execfile(os.path.abspath("___code___.py"))
->   File "", line 1, in<module>
->
->   File 
"/private/var/folders/bc/bcpFbanYErusTUkLXieJfE+++TI/-Tmp-/tmpy0Ob9z/___code___.py", 
line 3, in<module>
->     find_root(erseno(x),_sage_const_2 ,_sage_const_10 ,xtol=_sage_const_0p01 
)
->   File "", line 1, in<module>
->
->   File 
"/private/var/folders/bc/bcpFbanYErusTUkLXieJfE+++TI/-Tmp-/tmp87jRdJ/___code___.py",
 line 4, in erseno
->     return _sage_const_2 *arcsin(b*sin(gangle)/_sage_const_2 
/r)-(Nrib-_sage_const_1 )*theta(dz2(x))/_sage_const_2 -(Nrib+_sage_const_1 
)*theta(x)/_sage_const_2 ;
->   File 
"/private/var/folders/bc/bcpFbanYErusTUkLXieJfE+++TI/-Tmp-/tmps88obK/___code___.py",
 line 11, in theta
->     return angle;
->UnboundLocalError: local variable 'angle' referenced before assignment


So which of your "if" conditions is true when the input is the variable x? I think that's the problem---none of the conditions is true, so angle is never set, so you are trying to return an undefined variable.


The find_root function takes in just a function (not a function evaluated at x), so the call should look something like:

find_root(erseno, xmin, xmax)

However, it seems that there is another problem with a NaN coming up. I just posted about this in another thread.

Thanks,

Jason


--
Jason Grout

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

Reply via email to