ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 01 Oct 2016 15:39:00 -0500How can I find the sum of a series of integers with powers eg, n^(n 1)?http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/ I'm trying to find the sage code that will calculate the sum of 1^2 + 3^4 + 5^6....+107^108 and I'm totally stumped. Any help would be greatly appreciated. Thank you!Fri, 30 Sep 2016 16:56:26 -0500http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/Answer by tmonteil for <p>I'm trying to find the sage code that will calculate the sum of 1^2 + 3^4 + 5^6....+107^108 and I'm totally stumped. Any help would be greatly appreciated. Thank you!</p>
http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?answer=35003#post-id-35003This looks like homework. Here are some hints:
- to create the list of the terms, search for *list comprehension*,
- to get only odd numbers, note that the `range` function has a `step` option, so that you can jump 2 by 2,
- then use the `sum` function to sum all elements of the list you obtained.
The result should start with `149` and end with `478`.
Sat, 01 Oct 2016 04:13:43 -0500http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?answer=35003#post-id-35003Comment by tmonteil for <p>This looks like homework. Here are some hints:</p>
<ul>
<li>to create the list of the terms, search for <em>list comprehension</em>,</li>
<li>to get only odd numbers, note that the <code>range</code> function has a <code>step</code> option, so that you can jump 2 by 2,</li>
<li>then use the <code>sum</code> function to sum all elements of the list you obtained.</li>
</ul>
<p>The result should start with <code>149</code> and end with <code>478</code>.</p>
http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?comment=35021#post-id-35021^_^ .Sat, 01 Oct 2016 15:38:06 -0500http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?comment=35021#post-id-35021Comment by SDawkins for <p>This looks like homework. Here are some hints:</p>
<ul>
<li>to create the list of the terms, search for <em>list comprehension</em>,</li>
<li>to get only odd numbers, note that the <code>range</code> function has a <code>step</code> option, so that you can jump 2 by 2,</li>
<li>then use the <code>sum</code> function to sum all elements of the list you obtained.</li>
</ul>
<p>The result should start with <code>149</code> and end with <code>478</code>.</p>
http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?comment=35019#post-id-35019Super, thanks so much for your help.Sat, 01 Oct 2016 15:36:00 -0500http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?comment=35019#post-id-35019Answer by SDawkins for <p>I'm trying to find the sage code that will calculate the sum of 1^2 + 3^4 + 5^6....+107^108 and I'm totally stumped. Any help would be greatly appreciated. Thank you!</p>
http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?answer=35020#post-id-35020sum([ i^(i+1) for i in [1, 3, 5..107] ])Sat, 01 Oct 2016 15:36:06 -0500http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?answer=35020#post-id-35020Comment by tmonteil for <p>sum([ i^(i+1) for i in [1, 3, 5..107] ])</p>
http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?comment=35022#post-id-35022Amazing, i did not know that such ellipsis was able to guess the step !Sat, 01 Oct 2016 15:39:00 -0500http://ask.sagemath.org/question/35002/how-can-i-find-the-sum-of-a-series-of-integers-with-powers-eg-nn-1/?comment=35022#post-id-35022