Matt Owen

source code for "files/robots quadrature/fitness.r"

return to portfolio
  1.  # matt owen
  2.  
  3.  
  4.  # compute which partition a point belongs to
  5.  findpartition <- function (x, v) {
  6.   v <- sort(v)
  7.   maximum <- length(v)
  8.   v <- (x < v)*(1:length(v))-1
  9.   v <- v[v != -1]
  10.   min(v, maximum)+1
  11.  }
  12.  
  13.  # get a list of which segment something belongs to
  14.  findpartitions <- function (x, v) {
  15.   lis <- c()
  16.   for (el in x)
  17.   lis <- c(lis, findpartition(el, v))
  18.   lis
  19.  }
  20.  
  21.  
  22.  # output image file
  23.  png(file='plots.png')
  24.  plot(x, y(x), col='red')
  25.  lines(v, fapply(pw, v), col='blue')