source code for "files/robots quadrature/fitness.r"
return to portfolio
- # matt owen
- # compute which partition a point belongs to
- findpartition <- function (x, v) {
- v <- sort(v)
- maximum <- length(v)
- v <- (x < v)*(1:length(v))-1
- v <- v[v != -1]
- min(v, maximum)+1
- }
- # get a list of which segment something belongs to
- findpartitions <- function (x, v) {
- lis <- c()
- for (el in x)
- lis <- c(lis, findpartition(el, v))
- lis
- }
- # output image file
- png(file='plots.png')
- plot(x, y(x), col='red')
- lines(v, fapply(pw, v), col='blue')