Description Usage Arguments Value Examples
Takes values of a function evaluated on a grid and computes an approximate value on the interior of the grid using linear interpolation.
1 |
pt |
An (x,y,z) vector at which to approximately evaluate a function |
x |
A vector of x-values |
y |
A vector of y-values |
z |
A vector of z-values |
m_f |
The matrix of function values on the grid x \times y \times z. Must be ordered vertically by R=≤ft[ \begin{array}{cc} f(x_1, y_1, z_1) & f(x_1, y_1, z_2) \\ f(x_1, y_2, z_1) & f(x_1, y_2, z_2) \\ f(x_2, y_1, z_1) & f(x_2, y_1, z_2) \\ f(x_2, y_2, z_1) & f(x_2, y_2, z_2) \end{array}\right] |
n_x |
An integer. The length of |
n_y |
An integer. The length of |
n_z |
An integer. The length of |
Returns the trilinear interpolation of (x,y,z,f) evaluated at pt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | f <- function(pt) pt[1] + pt[2] * pt[3] - pt[3] * pt[1]
# An arbitrary function
nn <- 7
# Number of points at which the interpolating grid is defined
v.x <- v.y <- v.z <- 1:nn
# The vector of x, y, and z values (need not all be the same)
m.xy <- cbind( rep( v.x, each=nn), rep( v.y, nn ) )
# The matrix of (x,y) values at which to evaluate f
v.f <- t( apply( m.xy, 1, function( xy ) sapply( v.z, function(z) f( c( xy, z ) ) ) ) )
# The matrix of the z-values
test.pt <- 1:3
print(f(test.pt))
print(trilin( test.pt, v.x, v.y, v.z, v.f, 7, 7, 7 ) )
# Is exact at grid points
test.pt.2 <- 1:3 + .2
print(f(test.pt.2))
print(trilin( test.pt.2, v.x, v.y, v.z, v.f, 7, 7, 7 ) )
# Approximation is still exact with quadratic functions
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.