# Calculating terms of a series

Is there any way to calculate terms of a series which Sage is unable to find a closed-form expression for?

For example, how do I calculate the first ten terms of a in the following example?

sage: a = sum(sqrt(x), x, 0, oo)
sage: a
sum(sqrt(x), x, 0, +Infinity)

edit retag close merge delete

1

What do you mean by "first ten terms"? Do you mean this sage: a = sum(sqrt(x), x, 0, 10) Also, what do you mean by "closed form expression"? This sum is not even convergent.

( 2013-04-02 01:46:38 -0600 )edit

Yes, but I was wondering whether it can be done from the already-existing object.

( 2013-04-02 20:20:34 -0600 )edit

Sort by ยป oldest newest most voted

You defined

sage: a = sum(sqrt(x), x, 0, oo); a
sum(sqrt(x), x, 0, +Infinity)


Let us explore this object.

sage: a.parent()
Symbolic Ring


Typing a. and pressing the tab key, we find among other methods the following two.

sage: a.operator()
sum
sage: a.operands()
[sqrt(x), x, 0, +Infinity]


So we can define a function that will replace +Infinity by n:

sage: def partial(a,n):
....:     return a.operator()(*(a.operands()[:-1]+[n]))
....:
sage: partial(a,10)
sum(sqrt(x), x, 0, 10)


and use it to get the first few partial sums:

sage: for n in xrange(5r):
....:     print partial(a,n)
....:
sum(sqrt(x), x, 0, 0)
sum(sqrt(x), x, 0, 1)
sum(sqrt(x), x, 0, 2)
sum(sqrt(x), x, 0, 3)
sum(sqrt(x), x, 0, 4)

more

Thanks, this is what I was looking for.

( 2013-04-15 09:19:00 -0600 )edit

Perhaps I am misinterpreting your question, but how about the following:

a = sum(sqrt(x), x, 0, 9)
print a
print a.n()

more

Yes, I know that can be done. I was just wondering whether there was a way to calculate terms from the object initialized with infinity as the upper bound.

( 2013-04-02 20:19:57 -0600 )edit

Please start posting anonymously - your entry will be published after you log in or create a new account.