ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 Apr 2013 16:19:00 +0200Calculating terms of a serieshttps://ask.sagemath.org/question/9965/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)
Tue, 02 Apr 2013 02:45:49 +0200https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/Comment by Eviatar Bach for <p>Is there any way to calculate terms of a series which Sage is unable to find a closed-form expression for?</p>
<p>For example, how do I calculate the first ten terms of <code>a</code> in the following example?</p>
<pre><code>sage: a = sum(sqrt(x), x, 0, oo)
sage: a
sum(sqrt(x), x, 0, +Infinity)
</code></pre>
https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17955#post-id-17955Yes, but I was wondering whether it can be done from the already-existing object.Wed, 03 Apr 2013 03:20:34 +0200https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17955#post-id-17955Comment by ppurka for <p>Is there any way to calculate terms of a series which Sage is unable to find a closed-form expression for?</p>
<p>For example, how do I calculate the first ten terms of <code>a</code> in the following example?</p>
<pre><code>sage: a = sum(sqrt(x), x, 0, oo)
sage: a
sum(sqrt(x), x, 0, +Infinity)
</code></pre>
https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17971#post-id-17971What 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.Tue, 02 Apr 2013 08:46:38 +0200https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17971#post-id-17971Answer by calc314 for <p>Is there any way to calculate terms of a series which Sage is unable to find a closed-form expression for?</p>
<p>For example, how do I calculate the first ten terms of <code>a</code> in the following example?</p>
<pre><code>sage: a = sum(sqrt(x), x, 0, oo)
sage: a
sum(sqrt(x), x, 0, +Infinity)
</code></pre>
https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?answer=14719#post-id-14719Perhaps I am misinterpreting your question, but how about the following:
a = sum(sqrt(x), x, 0, 9)
print a
print a.n()
Tue, 02 Apr 2013 10:47:27 +0200https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?answer=14719#post-id-14719Comment by Eviatar Bach for <p>Perhaps I am misinterpreting your question, but how about the following:</p>
<pre><code>a = sum(sqrt(x), x, 0, 9)
print a
print a.n()
</code></pre>
https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17956#post-id-17956Yes, 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.Wed, 03 Apr 2013 03:19:57 +0200https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17956#post-id-17956Answer by slelievre for <p>Is there any way to calculate terms of a series which Sage is unable to find a closed-form expression for?</p>
<p>For example, how do I calculate the first ten terms of <code>a</code> in the following example?</p>
<pre><code>sage: a = sum(sqrt(x), x, 0, oo)
sage: a
sum(sqrt(x), x, 0, +Infinity)
</code></pre>
https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?answer=14787#post-id-14787You 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)
Mon, 15 Apr 2013 08:59:58 +0200https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?answer=14787#post-id-14787Comment by Eviatar Bach for <p>You defined</p>
<pre><code>sage: a = sum(sqrt(x), x, 0, oo); a
sum(sqrt(x), x, 0, +Infinity)
</code></pre>
<p>Let us explore this object.</p>
<pre><code>sage: a.parent()
Symbolic Ring
</code></pre>
<p>Typing <code>a.</code> and pressing the tab key, we find among other
methods the following two.</p>
<pre><code>sage: a.operator()
sum
sage: a.operands()
[sqrt(x), x, 0, +Infinity]
</code></pre>
<p>So we can define a function that will replace <code>+Infinity</code> by <code>n</code>:</p>
<pre><code>sage: def partial(a,n):
....: return a.operator()(*(a.operands()[:-1]+[n]))
....:
sage: partial(a,10)
sum(sqrt(x), x, 0, 10)
</code></pre>
<p>and use it to get the first few partial sums:</p>
<pre><code>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)
</code></pre>
https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17890#post-id-17890Thanks, this is what I was looking for.Mon, 15 Apr 2013 16:19:00 +0200https://ask.sagemath.org/question/9965/calculating-terms-of-a-series/?comment=17890#post-id-17890