On Sun, Feb 12, 2012 at 2:13 PM, mrkvon <[email protected]> wrote:
> Hello,
>
> what is wrong with this, please? I tried to sum some matrix elements
> and got error below. I tried to sum by other means (comment # and ##
> in example below) without problem. I even defined my own summation
> function (analogic to ##), which at the end made similar error.
> I don't think I try to evaluate numerically, so why this error?
Actually, you _are_ trying to evaluate numerically, simply not what
you thought you were. :^)
The problem with
sum(lore4[k,k],k,0,3)
isn't the sum; it's the lore4[k,k]:
----
sage: lore4[k,k]
[...]
TypeError: cannot evaluate symbolic expression numerically
---
It's trying to convert the k to an integer index to access the matrix
elements. By the way, whenever Sage (or Python) gives me a TypeError
I break everything down into its pieces like this and try to find
which one is causing the problems. It doesn't always work, but I'd
say 75% of the time it's an input formatting error on my part that I
can find.
Anyway, I'm not sure if Sage matrices can be indexed by symbolic
variables like this. [Whenever I say you can't do something in Sage
someone proves me wrong, but I'm not familiar with the trick if there
is one.]
In this case, rather than using the symbolic sum 4-term calling style
(expression, var, v0, v1), I'd write it with a generator expression
instead:
---
sage: sum(lore4[k,k] for k in [0..3])
2*sinh(x) + 2
---
or something like that.
Doug
--
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