1

I have to perform multiple 2-d linear interpolations from the same input coordinates (x,y) to the same output coordinates (xo,yo). Only the data values (z) change every time (z1,z2,z3,...).

I have been using package interp on R. So far, I have been calling command "interp" multiple times. Like this:

# create data 
y <- rep(1:5,5)      # input coords
x <- rep(1:5,each=5)
z1 <- 1:25           # data
z2 <- 25:1
xo <- c(1.1,2.2,3.3) # output coords
yo <- c(2.2,3.3,4.4)

# interpolate 
library(interp)
z1.int <- interp(x,y,z1,xo,yo,output="points")[[3]]; z1.int
z2.int <- interp(x,y,z2,xo,yo,output="points")[[3]]; z2.int

# plot (optional)
layout(t(1:2))
plot(x,y,type='n'); text(x,y,z1,col='red'); text(xo,yo,z1.int)
plot(x,y,type='n'); text(x,y,z2,col='red'); text(xo,yo,z2.int)

However, I suspect that there is a way to drastically speed up my calculations. The interpolation procedure consists of a number of steps. I think that some of them only need to be performed once and then use their results multiple times for the multiple data vectors.

Is there a way to do that?

kdouv
  • 11
  • 4

0 Answers0