atan2 throws "divide by zero"

67 ogledov
Preskoči na prvo neprebrano sporočilo

G B

neprebran,
17. mar. 2010, 20:38:2917. 3. 10
do sage-support
While waiting to be approved, I think I narrowed this down to a very
simple test case.

atan2(3,0) --> 1/2*pi
atan2(-3,0) --> -1/2*pi
atan2(pi,0) --> 1/2*pi
atan2(-pi,0) --> RuntimeError: power::eval(): division by zero

Any ideas how to get around this?

Thanks--
Greg

Here's the full traceback:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_34.py", line 9, in <module>
open("___code___.py","w").write("# -*- coding: utf-8 -*-\n" +
_support_.preparse_worksheet_cell(base64.b64decode("YXRhbjIoLXBpLDAp"),globals())
+"\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>

File "/private/var/folders/ol/olxcekVE2RWirE+1YxlblU+++TI/-Tmp-/
tmphh0DH2/___code___.py", line 3, in <module>
atan2(-pi,_sage_const_0 )
File "", line 1, in <module>

File "function.pyx", line 709, in
sage.symbolic.function.GinacFunction.__call__ (sage/symbolic/
function.cpp:6394)
File "function.pyx", line 430, in
sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:
4448)
RuntimeError: power::eval(): division by zero

G B

neprebran,
17. mar. 2010, 22:11:4617. 3. 10
do sage-support
Should have also mentioned:

Sage 4.3.3
OS X 10.6.2
64bit Intel
MacBook Pro

Alec Mihailovs

neprebran,
18. mar. 2010, 02:34:1118. 3. 10
do sage-support

On Mar 17, 9:11 pm, G B <g.c.b.at.w...@gmail.com> wrote:

> atan2(-pi,0) -->  RuntimeError: power::eval(): division by zero

I got the same in the new 4.3.4.rc0 Sage version that I've just
installed.

Playing with that, I noticed also the following strange thing:

sage: n(atan2(-sqrt(2),0))

-1/2*pi

While it looks correct, it is not the answer that n should give.

Alec Mihailovs

Alec Mihailovs

neprebran,
18. mar. 2010, 16:40:0918. 3. 10
do sage-support
On Mar 17, 8:38 pm, G B <g.c.b.at.w...@gmail.com> wrote:

> atan2(-pi,0) -->  RuntimeError: power::eval(): division by zero
>
> Any ideas how to get around this?

A simple workaround is

sage: from sympy import atan2
sage: atan2(-pi,0)

-pi/2

Alec Mihaiovs

G B

neprebran,
18. mar. 2010, 20:10:4118. 3. 10
do sage-support
Thanks. I tried that but it's causing different problems:
-----------------------
from sympy import atan2
var('omega,t,x,y,r,Theta')
Theta(t)=omega*t
x(t)=r*cos(Theta(t))
y(t)=r*sin(Theta(t))
dx=diff(x,t)
ddx=diff(dx,t)
dy=diff(y,t)
ddy=diff(dy,t)
v_a(t)=atan2(dy(t),dx(t))
v_a
--------------------------

I get: AttributeError: 'atan2' object has no attribute '_sage_'

My original code had this for that second last line:
v_a(t)=atan2(dy(t),dx(t)).substitute(r=10,omega=(2*pi/60))


and it throws: AttributeError: 'atan2' object has no attribute
'substitute'

The code with the .substitute line seems to work for (t%30 <> 0) so I
think I've formatted my equations properly.

Apologies if I'm doing something horribly hackish-- I'm new to Sage.

Any other ideas?

Thanks--
Greg

Ondrej Certik

neprebran,
19. mar. 2010, 22:03:5519. 3. 10
do sage-s...@googlegroups.com
On Thu, Mar 18, 2010 at 5:10 PM, G B <g.c.b....@gmail.com> wrote:
> Thanks.  I tried that but it's causing different problems:
> -----------------------
> from sympy import atan2
> var('omega,t,x,y,r,Theta')
> Theta(t)=omega*t
> x(t)=r*cos(Theta(t))
> y(t)=r*sin(Theta(t))
> dx=diff(x,t)
> ddx=diff(dx,t)
> dy=diff(y,t)
> ddy=diff(dy,t)
> v_a(t)=atan2(dy(t),dx(t))
> v_a
> --------------------------
>
> I get: AttributeError: 'atan2' object has no attribute '_sage_'

This is a bug in sympy, I've fixed that in sympy, currently the
patches are waiting for a review. When we update the sympy package in
sage, here is what you'll get:

sage: var('omega,t,x,y,r,Theta')
(omega, t, x, y, r, Theta)
sage: Theta(t)=omega*t
sage: x(t)=r*cos(Theta(t))
sage: y(t)=r*sin(Theta(t))
sage: dx=diff(x,t)
sage: ddx=diff(dx,t)
sage: dy=diff(y,t)
sage: ddy=diff(dy,t)
sage: v_a(t)=atan2(dy(t),dx(t))
sage: v_a
t |--> arctan2(omega*r*cos(omega*t), -omega*r*sin(omega*t))


>
> My original code had this for that second last line:
> v_a(t)=atan2(dy(t),dx(t)).substitute(r=10,omega=(2*pi/60))
>
>
> and it throws: AttributeError: 'atan2' object has no attribute
> 'substitute'

in the above code, you are using sympy, and thus you have to use:

sage: atan2(dy(t),dx(t)).subs({r:10, omega:2*pi/60})
arctan2(1/3*pi*cos(1/30*pi*t), -1/3*pi*sin(1/30*pi*t))

and it should work. Note that this doesn't work in the current sage,
but it will work when we update sympy.

We are also facing some technical problem, that the latest mpmath in
sympy doesn't work with sage:

http://code.google.com/p/sympy/issues/detail?id=1865

so the newest sympy fails to import, but we'll fix it too.

Ondrej

Ondrej Certik

neprebran,
19. mar. 2010, 22:32:1719. 3. 10
do sage-s...@googlegroups.com
On Fri, Mar 19, 2010 at 7:03 PM, Ondrej Certik <ond...@certik.cz> wrote:
> On Thu, Mar 18, 2010 at 5:10 PM, G B <g.c.b....@gmail.com> wrote:
>> Thanks.  I tried that but it's causing different problems:
>> -----------------------
>> from sympy import atan2
>> var('omega,t,x,y,r,Theta')
>> Theta(t)=omega*t
>> x(t)=r*cos(Theta(t))
>> y(t)=r*sin(Theta(t))
>> dx=diff(x,t)
>> ddx=diff(dx,t)
>> dy=diff(y,t)
>> ddy=diff(dy,t)
>> v_a(t)=atan2(dy(t),dx(t))
>> v_a
>> --------------------------
>>
>> I get: AttributeError: 'atan2' object has no attribute '_sage_'
>
> This is a bug in sympy, I've fixed that in sympy, currently the
> patches are waiting for a review. When we update the sympy package in

Also a small fix to sage has to be done, I posted the patch here:

http://trac.sagemath.org/sage_trac/ticket/8564

Greg, could you please review it?

Thanks,
Ondrej

Alec Mihailovs

neprebran,
20. mar. 2010, 01:47:1220. 3. 10
do sage-support
Also, simplification might be improved. In particular,

sage: atan(sin(1)/cos(1)).full_simplify()

arctan(sin(1)/cos(1))

while

atan(tan(1)).simplify()

1

Alec Mihailovs

G B

neprebran,
22. mar. 2010, 18:35:2022. 3. 10
do sage-support
Hi Ondrej--

Sorry to turn helpless, but I'm not sure how to apply the patch. I'm
working from a binary install for OS X. Would I need to rebuild from
source, or can I apply the patch to one of the implementation files in
the bundle? It looks like you've just changed a lookup table?

Thanks for following up.

Thanks--
Greg


On Mar 19, 7:32 pm, Ondrej Certik <ond...@certik.cz> wrote:
> On Fri, Mar 19, 2010 at 7:03 PM, Ondrej Certik <ond...@certik.cz> wrote:

Sporočilo je izbrisano

Ondrej Certik

neprebran,
23. mar. 2010, 04:18:5223. 3. 10
do sage-s...@googlegroups.com
Hi Minh!

On Mon, Mar 22, 2010 at 8:55 PM, Minh Nguyen <nguye...@gmail.com> wrote:
> Hi Greg,


>
> On Tue, Mar 23, 2010 at 9:35 AM, G B <g.c.b....@gmail.com> wrote:
>> Hi Ondrej--
>>
>> Sorry to turn helpless, but I'm not sure how to apply the patch.  I'm
>> working from a binary install for OS X.
>

> Here is a quick-and-dirty way. I assume that you are using Sage 4.3.3
> or Sage 4.3.4. From the Sage command line, you could issue the
> following command to apply the relevant patch:
>
> sage: hg_sage.apply("http://trac.sagemath.org/sage_trac/raw-attachment/ticket/8564/sympy1.patch")
>
> After hitting the enter key, the relevant patch would be downloaded to
> your computer. A text editor would then load and you would be prompted
> to enter a "commit message". Just enter some text such as "fix atan2()
> conversions between Sage and SymPy", save your text, exit the text
> editor. If the editor is vi(m), enter the text, hit the ESC key, and
> type ":wq". If the editor is Emacs, enter the text, hold down the CTRL
> key, and type "xs" and "xc" in that order. Having exited the text
> editor, the relevant patch would be applied to your local copy of
> Sage. Now exit the Sage command line session. From the SAGE_ROOT
> directory of Sage, i.e. the Sage top-level directory, rebuild the Sage
> library as follows:
>
> $ ./sage -b main
>
> This would only rebuild the relevant parts that the patch changes.
> Most likely, the last command won't rebuild the whole Sage library.


>
>
>> Would I need to rebuild from
>> source,
>

> You don't need to rebuild Sage from source for this particular patch.


>
>
>> or can I apply the patch to one of the implementation files in
>> the bundle?
>

> Follow the direction as described above. If there is anything wrong,
> please let me know.


>
>
>> It looks like you've just changed a lookup table?
>

> The patch adds an entry to a dictionary, also known as a hash table or
> an associative array.

Thanks for all the detailed instructions. I also sent some patches
that we need to apply in sympy, fixing couple (related) bugs, so after
all is reviewed and in, I'll also update the whole sympy package and
ping you. But this patch above itself should imho fix the atan2 thing,
even with the current sympy in Sage.

Ondrej

G B

neprebran,
23. mar. 2010, 22:00:3423. 3. 10
do sage-support
I won't clutter the discussion with the full traceback unless someone
would find it interesting, but the hg_sage command failed with:

TypeError: 'NoneType' object is unsubscriptable.

I did enter the entire URL, I didn't just paste the abbreviated URL
displayed in the post.

On Mar 23, 1:18 am, Ondrej Certik <ond...@certik.cz> wrote:
> Hi Minh!
>
>
>
>
>
> On Mon, Mar 22, 2010 at 8:55 PM, Minh Nguyen <nguyenmi...@gmail.com> wrote:
> > Hi Greg,
>

> > On Tue, Mar 23, 2010 at 9:35 AM, G B <g.c.b.at.w...@gmail.com> wrote:
> >> Hi Ondrej--
>
> >> Sorry to turn helpless, but I'm not sure how to apply the patch.  I'm
> >> working from a binary install for OS X.
>
> > Here is a quick-and-dirty way. I assume that you are using Sage 4.3.3
> > or Sage 4.3.4. From the Sage command line, you could issue the
> > following command to apply the relevant patch:
>

> > sage: hg_sage.apply("http://trac.sagemath.org/sage_trac/raw-attachment/ticket/8564/sympy1....")

G B

neprebran,
30. mar. 2010, 16:59:1130. 3. 10
do sage-support
For anyone interested, it looks as though the GiNaC project has
released a fix:
http://www.cebix.net/pipermail/ginac-devel/2010-March/001732.html

I've posted this to the dev list as well.

Cheers--
Greg

Odgovori vsem
Odgovori avtorju
Posreduj
0 novih sporočil