Failed Integration

42 views
Skip to first unread message

Chris Maness

unread,
Jul 2, 2014, 7:33:33 PM7/2/14
to sage-s...@googlegroups.com
I don't see what the issue is with the code below:

phinS=e^(i*n*pi*x/a);
phim=e^(-i*m*pi*x/a);
a=var('a');
assume(a > 0);
n=1;
m=1;
integrate(phinS*phim,x,-a,a)

I get this undecipherable error:

Traceback (most recent call last): integrate(phinS*phim,x,-a,a)
File "", line 1, in <module>

File "/private/var/folders/ql/h8_whzn142g4zv11m77dlh4h0000gn/T/tmpCThsN_/___code___.py",
line 3, in <module>
phinS=e**(i*n*pi*x/a);
File "element.pyx", line 1715, in
sage.structure.element.RingElement.__mul__
(sage/structure/element.c:15355)
File "coerce.pyx", line 847, in
sage.structure.coerce.CoercionModel_cache_maps.bin_op
(sage/structure/coerce.c:8326)
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and
'<type 'function'>'

Any suggestions?

Thanks,
Chirs

Nils Bruin

unread,
Jul 2, 2014, 9:03:31 PM7/2/14
to sage-s...@googlegroups.com, ch...@chrismaness.com
On Wednesday, July 2, 2014 4:33:33 PM UTC-7, Chris Maness wrote:
I don't see what the issue is with the code below:

phinS=e^(i*n*pi*x/a);
phim=e^(-i*m*pi*x/a);
a=var('a');
assume(a > 0);
n=1;
m=1;
integrate(phinS*phim,x,-a,a)
 
For one thing, it doesn't execute, and it doesn't produce the error message that you mention. n,m,a are not defined when the assignments to phinS and phim are executed, so they don't succeed.

Fixing the order of execution leads to a straightforward answer for me:

sage: a=var('a');
sage: assume(a > 0);
sage: n=1;
sage: m=1;
sage: phinS=e^(i*n*pi*x/a);
sage: phim=e^(-i*m*pi*x/a);
sage: integrate(phinS*phim,x,-a,a)
2*a

so I suspect you had other, inconsistent definitions lying around when you ran into the error. It's always good to try and see if you can reproduce results in a fresh sage session, with a small and concise script (you had the latter, but you didn't try to run it in a fresh session)

Nils Bruin

unread,
Jul 2, 2014, 9:06:17 PM7/2/14
to sage-s...@googlegroups.com, ch...@chrismaness.com
On Wednesday, July 2, 2014 4:33:33 PM UTC-7, Chris Maness wrote:

TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and
'<type 'function'>'

This error is more concisely generated with:

 sage: x*n

TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and '<type 'function'>'

and it's due to this fact:

sage: n
<function sage.misc.functional.numerical_approx>

i.e., if you don't define n then you'll have that n is a python function which cannot fruitfully be multiplied with a symbolic expression.

Chris Maness

unread,
Jul 2, 2014, 9:31:07 PM7/2/14
to sage-s...@googlegroups.com
Ahhhh, that is the issue.

Thanks
Chris
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages