I have this two functions:
Hwave_1 <- function(t) {
ifelse(0 <= t & t <= 1 / 2, t, ifelse(1 / 2 < t & t <= 1, 1 - t, 0))
}
HaarI <-function(m,k,t){
ifelse(t > 1 | t < 0, "HaarErrorTimes", 2^((-m)/2)*Hwave_1((2^m)*t-k))
}
I'm trying to create a function as in the image
where the Z_nj=rnorm(1)
I tried to do some naive things like
simul_weiner<-function(t,m){
for(i in 0:(2^m-1)){result<-sum(rnorm(1)*HaarI(m,i,t))}
ifelse(n=0,rnorm(1)*HaarI(0,0,t),result+rnorm(1)*HaarI(0,0,t))
}
but it clearly doesnt work because sum()
is summing every entry, I dont know if there exist a workaround or another sum function that can help me make the code work.
EDIT: Steps to reproduce
#create times vector
times<-seq(from=0, to=1,by=2^(-5))
#call the function on times with any m you choose, i choose 2 for simplicity
simul_weiner(times,2)
It should output a list with the same number repeating.