|
INTERP2X.OMS
Script File:
# Description:
# Plots the bilinear interpolant of z = x^2 + y^2.
#
clear
# define 5 point x and y grids
xz = 10 * (seq(5) - 1) / 4. - 5.
yz = 10 * (seq(5)' - 1) / 6. - 5.
# fill out the grid values to 5 by 5 matrix
X = fillcols(xz, 5)
Y = fillrows(yz, 5)
# evaluate z on the 5 by 5 grid
# z(i, j) = xz(i)^2 + yz(j)^2
z = X^2 - Y^2
# define 20 point interpolation grids
xi = 10 * seq(20) / 20. - 5.
yi = 10 * seq(20)' / 20. - 5.
# interpolate from the 5 by 5 grid to
# the 20 by 20 grid
zi = interp2(z, xz, yz, xi, yi)
# plot the interpolated values
mesh(zi, "black", xi, yi)
gtitle("Bilinear Interpolation of x^2 - y^2")
Output:
|
|