In [1]:
import escape as esc
esc.require('0.9.7')
from escape.utils.widgets import show
import numpy as np
Loading material database from /home/dkor/Data/Development/workspace_escape/escape/python/src/escape/scattering/../data/mdb/materials.db
Linear interpolation functor¶
ESCAPE library supports basic piecewise linear interpolation which is functionally the same as provided by numpy library (see numpy.interp function).
The x-coordinates of the interpolated data points must be always increasing and there is no internal sorting procedure. If data points are not increasing the values returned by linear interpolation functor are meaningless.
In [2]:
X=esc.var("X")
xp = np.linspace(0, 2*np.pi, 100)
yp = np.sin(xp)
yinterp = esc.linterp(X, xp, yp)
show(yinterp, coordinates=np.linspace(0, 2*np.pi, 100), xlabel="X", ylabel="Y", title="Linear interpolation sin(X)")
linterp
supports complex forms of functions, like sin(F(X))
, where F(x)
is any function of variable X
.
In [3]:
X=esc.var("X")
xp = np.linspace(0, 2*np.pi, 100)
yp = np.sin(xp)
F = esc.abs(esc.cos(X))
yinterp = esc.linterp(F, xp, yp)
show(F, coordinates=np.linspace(0, 2*np.pi, 100), xlabel="X", ylabel="Y", title="F(X)=abs(cos(X))")
show(yinterp, coordinates=np.linspace(0, 2*np.pi, 100), xlabel="X", ylabel="Y", title="Linear interpolation sin(F(X))")
The values outside the interpolator coordinates range are equal to its nearest value boundary.
In [4]:
X=esc.var("X")
xp = np.linspace(0, 2*np.pi, 10)
yp = np.sin(xp)
F = esc.cos(X)
yinterp = esc.linterp(F, xp, yp)
show(F, coordinates=np.linspace(0, 2*np.pi, 100), xlabel="X", ylabel="Y", title="F(X)=cos(X)")
show(yinterp, coordinates=np.linspace(0, 2*np.pi, 100), xlabel="X", ylabel="Y", title="Linear interpolation sin(F(X))")
In [ ]: