Ask Your Question
2

Calculating terms of a series

asked 2013-04-01 19:45:49 -0500

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 01:46:38 -0500 )edit

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

Eviatar Bach gravatar imageEviatar Bach ( 2013-04-02 20:20:34 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-04-15 01:59:58 -0500

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 09:19:00 -0500 )edit
0

answered 2013-04-02 03:47:27 -0500

calc314 gravatar image

updated 2013-04-02 03:47:39 -0500

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-02 20:19:57 -0500 )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-01 19:45:49 -0500

Seen: 450 times

Last updated: Apr 15 '13