Ask Your Question
2

Calculating terms of a series

asked 2013-04-02 02:45:49 +0100

Eviatar Bach gravatar image

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 flag offensive close merge delete

Comments

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.

ppurka gravatar imageppurka ( 2013-04-02 08:46:38 +0100 )edit

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

Eviatar Bach gravatar imageEviatar Bach ( 2013-04-03 03:20:34 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-04-15 08:59:58 +0100

slelievre gravatar image

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)
edit flag offensive delete link more

Comments

Thanks, this is what I was looking for.

Eviatar Bach gravatar imageEviatar Bach ( 2013-04-15 16:19:00 +0100 )edit
0

answered 2013-04-02 10:47:27 +0100

calc314 gravatar image

updated 2013-04-02 10:47:39 +0100

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

a = sum(sqrt(x), x, 0, 9)
print a
print a.n()
edit flag offensive delete link more

Comments

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.

Eviatar Bach gravatar imageEviatar Bach ( 2013-04-03 03:19:57 +0100 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-04-02 02:45:49 +0100

Seen: 1,490 times

Last updated: Apr 15 '13