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
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
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.
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 .
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.
If you don't need an analitical solution, then you don't need symsum
. For example if you want to calculate
the you can simply use sum
sum([1:5])
Here is another example:
f = @(x) exp(-x)
sum(f([1:5]))
And another one with factorial
function:
g = @(n) 1 ./ factorial(n)
sum(g([0:5]))
the same, but without anonymous function:
sum(1 ./ factorial([0:5]))
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]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With