Question

I have wrote a piece of coding for expression of

sum(l(from 1 to n))
       sum(i(from 1 to m))
           sum(t(from 1 to m)
              (phil(i)*phil(t)*[I(X(l)<min(y(i),y(t))-z(i)z(t)]

Like this:

set.seed(1234567)    
z1<-runif(50,min=0,max=1);m=length(z1)    
z2<-z1;m=length(z1)
x<-rnorm(60);n=length(x)
y<-rnorm(50)*0.25
phil_z1_1<-sqrt(12*(z1/z1))
# using the sapply such that 
sum(sapply(1:n, function(l) {sum(sapply(1:m, function(i){sum(sapply(1:m,function(t){phil_z1_1[i]*phil_z1_1[t]*(x[l]<=min(y(i),y(t))-z[i]*z[t])}))}))

Unfortunately this did not work, as i could not get any results after running it

I got something like,

sum1<-sum(sapply(1:m, function(t){sum(sapply(1:m, function(i){sum(sapply(1:n,function(l){phil_z1_1[i]*phil_z1_1[t]*(x[l]<=min(y(i),y(t))-z[i]*z[t])}))}))
+

I do not understand what the symbol "+" means

Can anyone help me with this

Thanks in advance!!!

Was it helpful?

Solution

If I understand your formula correctly, you want first determine for which indizes l,i,t the expression min(y[i],y[t])-z[i]*z[t] is greater or equal to x[l], and then sum phil_z1_1[i]*phil_z1_1[t] over those indizes. Strangely, there is no l in latter expression.

Here is one way, but it is probably not the most efficient one:

set.seed(1234567)    
z1 <- runif(50,min=0,max=1)
z2 <- runif(50,min=0,max=1)
m <- length(z1)    
x <- rnorm(60)
n <- length(x)
y <- rnorm(50)*0.25
phil_z1_1 <- sqrt(12*(z1/z2))

args <- expand.grid(l=1:n, i=1:m, t=1:m)
args <- subset(args, x[l] <= pmin(y[i],y[t])-z1[i]*z2[t])
args <- transform(args, result=phil_z1_1[i]*phil_z1_1[t])

sum(args[,"result"])
[1] 1173920

Note that I renamed some variables, so this may not be what you wanted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top