I thought it should be an easy one but I have been scratching my head and couldn't find the correct way.
I would like to calculate a summation of series A:
A<-*summation((i=2 to i=s)*K(c1+c2(i-1)))
where k, c1 & c2 are fixed values.
Expand A, i would like to get the sum of all these:
K(c1+c2(2-1))+K(c1+c2(3-1))+.......K(c1+c2(s-1))
To do that in R, here is what I wrote:
A<-function(s){
for (i in 2:s){
c1=5
c2=13.6
k=10
sum(k*(c1+c2*(i-1)))
}}
but when I do
A(5)
it didn't come up with anything
So I modified the function and asked it to print what it did:
A<-function(s){
for (i in 2:s){
c1=5
c2=13.6
k=10
a<-sum(k*(c1+c2*(i-1)))
print(a)
}}
> A(5)
[1] 186
[1] 322
[1] 458
[1] 594
Apparently it didn't "sum" all of them but calculated them independently.
So what exactly is the correct codes for summation?
Thanks.