Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

summation series using octave

Tags:

matlab

octave

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
like image 518
com Avatar asked Oct 30 '13 10:10

com


People also ask

How do you sum all elements in a matrix octave?

Description. S = sum( A ) returns the sum of the elements of A along the first array dimension whose size does not equal 1. If A is a vector, then sum(A) returns the sum of the elements. If A is a matrix, then sum(A) returns a row vector containing the sum of each column.

How do you write a summation in Matlab?

F = symsum( f , k , a , b ) returns the sum of the series f with respect to the summation index k from the lower bound a to the upper bound b . If you do not specify k , symsum uses the variable determined by symvar as the summation index. If f is a constant, then the default variable is x .

How do you transpose in octave?

To interchange rows with columns, that is, to find the transpose of a vector or a matrix, use the apostrophe. For example, the command octave#:#> C = [4 7.5 -1]' will transform the row vector C = [4 7.5 -1] into a column vector.


1 Answers

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]))
like image 185
Leonid Beschastny Avatar answered Sep 19 '22 14:09

Leonid Beschastny