1 | attract(X, Y, k = 5)
|
X |
|
Y |
|
k |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (X, Y, k = 5)
{
l1coef <- l1fit(X, Y)$coef
X <- as.matrix(X)
nr <- dim(X)[1]
nc <- dim(X)[2] + 1
J <- 1:nc
dom <- matrix(nrow = k, ncol = nc)
par(mfrow = c(1, 2))
plot(X, Y)
title("a) 5 Elemental Starts")
for (i in 1:k) {
J <- sample(nr, nc)
if (abs(X[J[1]] - X[J[2]]) < 1/1e+08) {
slope <- 0
}
else {
slope <- (Y[J[1]] - Y[J[2]])/(X[J[1]] - X[J[2]])
}
int <- Y[J[1]] - slope * X[J[1]]
fit <- c(int, slope)
yhat <- X %*% fit[2:nc] + fit[1]
lines(X, yhat)
dom[i, ] <- conc2(X, Y, start = fit)$coef
}
plot(X, Y)
for (i in 1:k) {
fit <- dom[i, ]
yhat <- X %*% fit[2:nc] + fit[1]
lines(X, yhat)
}
title("b) The Corresponding Attractors")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.