recursiveCall <- function(x, N)
{
cat("length = ", length(x))
cat("vector x = ", x[1:2^N], "\n")
return (x)
}
PaulLevyBrownianMotion <- function(N)
{
cat("Paul Levy construction for N = ", N, "\n")
W = c(rnorm(2^N+1, 0, 1))
cat("length = ", length(W))
cat("Wstandard = ", W, "\n")
W <- recursiveCall(W[1:2^N+1], N)
return (W)
}
我的向量W在传递给另一个函数时似乎丢失了它的第一个组件。你能帮帮我吗?这是输出。
> W = PaulLevyBrownianMotion(2)
Paul Levy construction for N = 2
length = 5Wstandard = 0.08641454 1.616638 -0.8747996 0.6149899 0.2689501
length = 4vector x = 1.616638 -0.8747996 0.6149899 0.2689501
>
答案 0 :(得分:2)
W[1:2^N + 1]
没有将您的想法编入索引。首先构造向量1:2^N
,然后添加标量1
(因此每个元素增加1),从而导致元素2到结尾被选中。