recur_vec: function for vector recursive sequence calculation...

Description Usage Arguments Value Examples

View source: R/recur_vec.R

Description

function for vector recursive sequence calculation Recurpackage recur_vec package The input should have one vector and a sequence number indicator n , The vector should have more than one elements while the sequence number indicator n should be a positive integar (>n) The output is the final nth element of the sequence to calculate defined as following X_n = X_(n-1) + |X_(n-2) -X(n-3)|/2

Usage

1
recur_vec(x, n)

Arguments

x

x should be a vector with more than one elements. However, the function will only take the first three elements of the vector as the initial value as the recursive sequence initial value input

n

n should be a positive integer number

Value

The output is the final nth element of the sequence to calculate defined as following X_n = X_(n-1) + |X_(n-2) -X(n-3)|/2

Examples

1
2
3
recur_vec(x = c(2, 4, 3), n = 3)
recur_vec(x = c(2, 4, 3), n = 4)
recur_vec(x = c(2, 4, 3,5), n = 3)

fangfeiliu/recurpkg documentation built on Aug. 2, 2020, 1:50 a.m.