Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.3.0 - 日本語

Change language to:
English - Français - Português

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab manual >> Interpolation > linear_interpn

linear_interpn

n 次元線形補間

呼び出し手順

vp = linear_interpn(xp1,xp2,..,xpn, x1, ..., xn, v [,out_mode])

パラメータ

xp1, xp2, .., xpn

同じ大きさの実数ベクトル (または行列)

x1 ,x2, ..., xn

n次元の補間グリッドを定義する (最低でも2つの要素を有する)単調増加の行ベクトル

v

ベクトル ( n=1の場合), 行列 (n=2の場合) またはハイパー行列 ( n > 2の場合) で, グリッド点における補間関数の基準値を指定します.

out_mode

(オプションの) 文字列で, グリッド外の評価方法(捕外)を定義します.

vp

xp1, ..., xpnと同じ大きさのベクトルまたは行列

説明

n個のベクトルx1 ,x2,..., xnで定義された n次元グリッド とそのグリッドにおける関数(例えば f)の値を次のように指定すると:

この関数は, ベクトルxp1, xp2, ..., xpn(または行列)により定義された座標にある (以下 s と呼ぶ)グリッドから次のように fの線形補間を計算します:

out_mode パラメータは捕外の評価規則を設定します: Pi=(xp1(i),xp2(i),...,xpn(i)) とすると, out_mode は次の場合に評価規則を定義します:

その他の選択肢は以下があります:

"by_zero"

ゼロによる捕外が行われますa

"by_nan"

Nanによる捕外

"C0"

捕外が以下のように定義されます:

s(P) = s(proj(P)) where proj(P) is nearest point from P 
                  located on the grid boundary.
"natural"

捕外はその点に最も近いn線形パッチにより行われます.

"periodic"

s は周期的に拡張されます.

// example 1 : 1d linear interpolation
x = linspace(0,2*%pi,11);
y = sin(x);
xx = linspace(-2*%pi,4*%pi,400)';
yy = linear_interpn(xx, x, y, "periodic");
clf()
plot2d(xx,yy,style=2)
plot2d(x,y,style=-9, strf="000")
xtitle("linear interpolation of sin(x) with 11 interpolation points")

// example 2 : bilinear interpolation
n = 8;
x = linspace(0,2*%pi,n); y = x;
z = 2*sin(x')*sin(y);
xx = linspace(0,2*%pi, 40);
[xp,yp] = ndgrid(xx,xx);
zp = linear_interpn(xp,yp, x, y, z);
clf()
plot3d(xx, xx, zp, flag=[2 6 4])
[xg,yg] = ndgrid(x,x);
param3d1(xg,yg, list(z,-9*ones(1,n)), flag=[0 0])
xtitle("Bilinear interpolation of 2sin(x)sin(y)")
legends("interpolation points",-9,1)
xselect()

// example 3 : bilinear interpolation and experimentation
//             with all the outmode features
nx = 20; ny = 30;
x = linspace(0,1,nx);
y = linspace(0,2, ny);
[X,Y] = ndgrid(x,y);
z = 0.4*cos(2*%pi*X).*cos(%pi*Y);
nxp = 60 ; nyp = 120;
xp = linspace(-0.5,1.5, nxp);
yp = linspace(-0.5,2.5, nyp);
[XP,YP] = ndgrid(xp,yp);
zp1 = linear_interpn(XP, YP, x, y, z, "natural");
zp2 = linear_interpn(XP, YP, x, y, z, "periodic");
zp3 = linear_interpn(XP, YP, x, y, z, "C0");
zp4 = linear_interpn(XP, YP, x, y, z, "by_zero");
zp5 = linear_interpn(XP, YP, x, y, z, "by_nan");
clf()
subplot(2,3,1)
plot3d(x, y, z, leg="x@y@z", flag = [2 4 4])
xtitle("initial function 0.4 cos(2 pi x) cos(pi y)")
subplot(2,3,2)
plot3d(xp, yp, zp1, leg="x@y@z", flag = [2 4 4])
xtitle("Natural")
subplot(2,3,3)
plot3d(xp, yp, zp2, leg="x@y@z", flag = [2 4 4])
xtitle("Periodic")
subplot(2,3,4)
plot3d(xp, yp, zp3, leg="x@y@z", flag = [2 4 4])
xtitle("C0")
subplot(2,3,5)
plot3d(xp, yp, zp4, leg="x@y@z", flag = [2 4 4])
xtitle("by_zero")
subplot(2,3,6)
plot3d(xp, yp, zp5, leg="x@y@z", flag = [2 4 4])
xtitle("by_nan")
xselect()

// example 4 : trilinear interpolation (see splin3d help
//             page which have the same example with
//             tricubic spline interpolation)
exec("SCI/demos/interp/interp_demo.sci") 
func =  "v=(x-0.5).^2 + (y-0.5).^3 + (z-0.5).^2";
deff("v=f(x,y,z)",func);
n = 5; 
x = linspace(0,1,n); y=x; z=x;
[X,Y,Z] = ndgrid(x,y,z);
V = f(X,Y,Z);
// compute (and display) the linear interpolant on some slices
m = 41;
dir = ["z="  "z="  "z="  "x="  "y="];
val = [ 0.1   0.5   0.9   0.5   0.5];
ebox = [0 1 0 1 0 1];

XF=[]; YF=[]; ZF=[]; VF=[];
for i = 1:length(val)
  [Xm,Xp,Ym,Yp,Zm,Zp] = slice_parallelepiped(dir(i), val(i), ebox, m, m, m);
  Vm = linear_interpn(Xm,Ym,Zm, x, y, z, V);
  [xf,yf,zf,vf] = nf3dq(Xm,Ym,Zm,Vm,1);
  XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
  Vp =  linear_interpn(Xp,Yp,Zp, x, y, z, V);
  [xf,yf,zf,vf] = nf3dq(Xp,Yp,Zp,Vp,1);
  XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
end
nb_col = 128;
vmin = min(VF); vmax = max(VF);
color = dsearch(VF,linspace(vmin,vmax,nb_col+1));
xset("colormap",jetcolormap(nb_col));
clf()
xset("hidden3d",xget("background"))
colorbar(vmin,vmax)
plot3d(XF, YF, list(ZF,color), flag=[-1 6 4])
xtitle("tri-linear interpolation of "+func)
xselect()

Authors

B. Pincon

<< intsplin Interpolation lsq_splin >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Wed Jan 26 16:25:05 CET 2011