An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090501/eaab87cd/attachment-0001.pl>
Double summation limits
4 messages · Orestis Chrysafis, Ron Michael, David Winsemius
Perhaps:
SSCxy <- function(z) {tail(sapply(0:z, function (x) sum(sapply(0:x,
function(y) sum(choose(x+y, y))))), 1) }
> SSCxy(5)
[1] 462
See also:
http://www.research.att.com/~njas/sequences/?q=1%2C3%2C10%2C35%2C126%2C462&sort=0&fmt=0&language=english&go=Search
On May 1, 2009, at 3:45 PM, Orestis Chrysafis wrote:
Dear R experts
I need to write a function that incorporates double summation, the
problem
being that the upper limit of the second summation is the index of
the first
summation, i.e:
sum_{j=0}^{x} sum_{i=0}^{j} choose(i+j, i)
where x variable or constant, doesn't matter.
The following code obviously doesn't work:
f=function(x) {j=0:x; i=0:j; sum( choose(i+j,i) ) }
Can you help?
Thanks in advance,
Orestis Chrysafis
School of Mathematics
University of Sheffield
David Winsemius, MD Heritage Laboratories West Hartford, CT
Can anyone please explain me why it is not coming? I have done following :
j=1 i=0:j; sum( choose(i+j,i) )
[1] 3
j=2 i=0:j; sum( choose(i+j,i) )
[1] 10
j=3 i=0:j; sum( choose(i+j,i) )
[1] 35
j=0:3; i=0:j; sum( choose(i+j,i) )
Warning message: In 0:j : numerical expression has 4 elements: only the first used [1] 4 Here if value of "j" is given independently it is ok. However as soon as "j" is used in loop it fails? Why it is happening? Is there any mathematics behind that?
Orestis Chrysafis wrote:
Dear R experts
I need to write a function that incorporates double summation, the problem
being that the upper limit of the second summation is the index of the
first
summation, i.e:
sum_{j=0}^{x} sum_{i=0}^{j} choose(i+j, i)
where x variable or constant, doesn't matter.
The following code obviously doesn't work:
f=function(x) {j=0:x; i=0:j; sum( choose(i+j,i) ) }
Can you help?
Thanks in advance,
Orestis Chrysafis
School of Mathematics
University of Sheffield
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
View this message in context: http://www.nabble.com/Double-summation-limits-tp23341171p23342887.html Sent from the R help mailing list archive at Nabble.com.
On May 2, 2009, at 12:18 AM, RON70 wrote:
Can anyone please explain me why it is not coming? I have done following :
j=1 i=0:j; sum( choose(i+j,i) )
[1] 3
j=2 i=0:j; sum( choose(i+j,i) )
[1] 10
j=3 i=0:j; sum( choose(i+j,i) )
[1] 35
j=0:3; i=0:j; sum( choose(i+j,i) )
Warning message: In 0:j : numerical expression has 4 elements: only the first used [1] 4 Here if value of "j" is given independently it is ok. However as soon as "j" is used in loop it fails?
What loop? You made j a vector and then tried to treat it like a single value. You even got an informative error message: "Warning message: In 0:j : numerical expression has 4 elements: only the first used"
Why it is happening? Is there any mathematics behind that?
Read for meaning.
Orestis Chrysafis wrote:
Dear R experts
I need to write a function that incorporates double summation, the
problem
being that the upper limit of the second summation is the index of
the
first
summation, i.e:
sum_{j=0}^{x} sum_{i=0}^{j} choose(i+j, i)
where x variable or constant, doesn't matter.
The following code obviously doesn't work:
f=function(x) {j=0:x; i=0:j; sum( choose(i+j,i) ) }
Can you help?
Thanks in advance,
Orestis Chrysafis
School of Mathematics
University of Sheffield
David Winsemius, MD Heritage Laboratories West Hartford, CT