1
$\begingroup$

Suppose we need to compute the sum in Maple,

$ \sum_{i = 0}^{10} 2^i $,

We can use the command,

sum(2^i, i = 0 .. 10)

Now, what if the indices are not consecutive like i = 0, 1, 2, 3, 4, [no 5], 6, 7, 8, 9, 10?

I tried sum(2^i, i = {0 .. 4, 6 .. 10}) but no luck.

$\endgroup$
  • $\begingroup$ Perhaps this is a better site for this question. $\endgroup$ – Miguelgondu Jan 3 '15 at 23:39
1
$\begingroup$

You should use the command "add" for instance

$$\rm {add}( 2^i, i=[0,1,2,5,6,9,10] )=1639.$$

Type in maple worksheet the following command $>?list$ to read about "list".

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks. If part of the sequence is consecutive, is there a way to use .. operator to generate that partial consecutive sequence then combine it with the rest of the whole sequence? $\endgroup$ – swoopin_swallow Jan 3 '15 at 23:49
  • $\begingroup$ @divingswallow: Try to use the sequence command in maple to generate the partial sequences, for example $ \rm{seq} ( j, j=0..4 ) $. $\endgroup$ – Mhenni Benghorbal Jan 3 '15 at 23:55
  • 1
    $\begingroup$ Thank you, it works; add(2^i, i = [seq(j, j = 0 .. 4), seq(k, k = 6 .. 10)]) = 2015. Happy new year!! $\endgroup$ – swoopin_swallow Jan 4 '15 at 0:00
  • $\begingroup$ @divingswallow: Good job! You are very welcome. $\endgroup$ – Mhenni Benghorbal Jan 4 '15 at 0:11
  • $\begingroup$ Use the dollar sign operator for a briefer command: add(2^i, i= [\$1..4, \$6..10]) $\endgroup$ – Carl Love Jan 4 '15 at 21:27
1
$\begingroup$

I think you can use

sum(2^i, i = 0 .. 10)-2^5
| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.