summation series using octave

com picture com · Oct 30, 2013 · Viewed 20.3k times · Source

Is it possible to do a summation series in Octave?

In matlab there is symsum function for it, however I didn't found anything similar for octave.

For example, I want to find the following sum

Summation


Addendum:

Whether it's possible to sum something like this

f = @(x) nchoosek(5,x)*0.1.^x*0.9.^(5-x)

sum(f([0:5]))

Failed with error

error: called from:
error:   /usr/share/octave/3.6.4/m/help/print_usage.m at line 87, column 5
error:   /usr/share/octave/3.6.4/m/specfun/nchoosek.m at line 95, column 5
error:    at line -1, column -1
error: evaluating argument list element number 1

Answer

Leonid Beschastny picture Leonid Beschastny · Oct 31, 2013

If you don't need an analitical solution, then you don't need symsum. For example if you want to calculate

\sum_{k=1}^{5} k

the you can simply use sum

sum([1:5])

Here is another example:

\sum_{k=1}^{5} \exp(-k)

f = @(x) exp(-x)
sum(f([1:5]))

And another one with factorial function:

\sum_{n=0}^{5} \frac{1}{n!} \approx e

g = @(n) 1 ./ factorial(n)
sum(g([0:5]))

the same, but without anonymous function:

sum(1 ./ factorial([0:5]))

Update

As for your last example, nchoosek allows only scalar arguments. So, you'll need additional arrayfun call:

f = @(x) nchoosek(5,x)*0.1.^x*0.9.^(5-x)
sum(arrayfun(f,[0:5]))