##### randomised sample #####
set.seed(16)
x = BridgeT(rnorm(30))
# when there are no repeated walues, the results of two functionas are identical
s1 = SplitByExtremum(x); s1
s2 = Split_MinMax_req(x); s2
# only one iteration, one min and on max.
s3 = Split_MinMax(x); s3
c(1, which.max(x), which.min(x), length(x))
# grafical iliustration:
plot(x, type="l")
points(s1, x[s1], col=2, cex=1, pch=19)
points(s3, x[s3], col=4, cex=2)
##### special sample #####
x = c(0, -0.5, -1, 2, -1, 3, -1, 0)
### in this case functions are not identical. SplitByExtremum makes a better job.
s1 = SplitByExtremum(x); s1
s2 = Split_MinMax_req(x); s2
Run the code above in your browser using DataLab