1 <?xml version="1.0" encoding="UTF-8"?>
2 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="linear_interpn" xml:lang="ja">
4 <refname>linear_interpn</refname>
5 <refpurpose>n 次元線形補間</refpurpose>
9 <synopsis>vp = linear_interpn(xp1,xp2,..,xpn, x1, ..., xn, v [,out_mode])</synopsis>
15 <term>xp1, xp2, .., xpn</term>
17 <para>同じ大きさの実数ベクトル (または行列)</para>
21 <term>x1 ,x2, ..., xn</term>
25 (最低でも2つの要素を有する)単調増加の行ベクトル
32 <para>ベクトル ( n=1の場合), 行列 (n=2の場合) またはハイパー行列 ( n
34 グリッド点における補間関数の基準値を指定します.
62 n個のベクトル<literal>x1 ,x2,..., xn</literal>で定義された n次元グリッド
63 とそのグリッドにおける関数(例えば <emphasis>f</emphasis>)の値を次のように指定すると:
68 <imagedata align="center" fileref="../mml/linear_interpn_equation1.mml"/>
73 この関数は, ベクトル<literal>xp1, xp2, ..., xpn</literal>(または行列)により定義された座標にある
74 (以下 <emphasis>s</emphasis> と呼ぶ)グリッドから次のように
75 <emphasis>f</emphasis>の線形補間を計算します:
80 <imagedata align="center" fileref="../mml/linear_interpn_equation2.mml"/>
85 <literal>out_mode</literal> パラメータは捕外の評価規則を設定します:
86 <emphasis>Pi=(xp1(i),xp2(i),...,xpn(i))</emphasis> とすると,
87 <literal>out_mode</literal> は次の場合に評価規則を定義します:
92 <imagedata align="center" fileref="../mml/linear_interpn_equation3.mml"/>
96 <para>その他の選択肢は以下があります:</para>
99 <term>"by_zero"</term>
101 <para>ゼロによる捕外が行われますa</para>
105 <term>"by_nan"</term>
107 <para>Nanによる捕外</para>
113 <para>捕外が以下のように定義されます:</para>
114 <programlisting role=""><![CDATA[
115 s(P) = s(proj(P)) where proj(P) is nearest point from P
116 located on the grid boundary.
121 <term>"natural"</term>
123 <para>捕外はその点に最も近いn線形パッチにより行われます.
128 <term>"periodic"</term>
131 <literal>s</literal> は周期的に拡張されます.
139 <programlisting role="example"><![CDATA[
140 // example 1 : 1d linear interpolation
141 x = linspace(0,2*%pi,11);
143 xx = linspace(-2*%pi,4*%pi,400)';
144 yy = linear_interpn(xx, x, y, "periodic");
146 plot2d(xx,yy,style=2)
147 plot2d(x,y,style=-9, strf="000")
148 xtitle("linear interpolation of sin(x) with 11 interpolation points")
150 // example 2 : bilinear interpolation
152 x = linspace(0,2*%pi,n); y = x;
153 z = 2*sin(x')*sin(y);
154 xx = linspace(0,2*%pi, 40);
155 [xp,yp] = ndgrid(xx,xx);
156 zp = linear_interpn(xp,yp, x, y, z);
158 plot3d(xx, xx, zp, flag=[2 6 4])
159 [xg,yg] = ndgrid(x,x);
160 param3d1(xg,yg, list(z,-9*ones(1,n)), flag=[0 0])
161 xtitle("Bilinear interpolation of 2sin(x)sin(y)")
162 legends("interpolation points",-9,1)
165 // example 3 : bilinear interpolation and experimentation
166 // with all the outmode features
168 x = linspace(0,1,nx);
169 y = linspace(0,2, ny);
171 z = 0.4*cos(2*%pi*X).*cos(%pi*Y);
172 nxp = 60 ; nyp = 120;
173 xp = linspace(-0.5,1.5, nxp);
174 yp = linspace(-0.5,2.5, nyp);
175 [XP,YP] = ndgrid(xp,yp);
176 zp1 = linear_interpn(XP, YP, x, y, z, "natural");
177 zp2 = linear_interpn(XP, YP, x, y, z, "periodic");
178 zp3 = linear_interpn(XP, YP, x, y, z, "C0");
179 zp4 = linear_interpn(XP, YP, x, y, z, "by_zero");
180 zp5 = linear_interpn(XP, YP, x, y, z, "by_nan");
183 plot3d(x, y, z, leg="x@y@z", flag = [2 4 4])
184 xtitle("initial function 0.4 cos(2 pi x) cos(pi y)")
186 plot3d(xp, yp, zp1, leg="x@y@z", flag = [2 4 4])
189 plot3d(xp, yp, zp2, leg="x@y@z", flag = [2 4 4])
192 plot3d(xp, yp, zp3, leg="x@y@z", flag = [2 4 4])
195 plot3d(xp, yp, zp4, leg="x@y@z", flag = [2 4 4])
198 plot3d(xp, yp, zp5, leg="x@y@z", flag = [2 4 4])
202 // example 4 : trilinear interpolation (see splin3d help
203 // page which have the same example with
204 // tricubic spline interpolation)
205 exec("SCI/modules/interpolation/demos/interp_demo.sci")
206 func = "v=(x-0.5).^2 + (y-0.5).^3 + (z-0.5).^2";
207 deff("v=f(x,y,z)",func);
209 x = linspace(0,1,n); y=x; z=x;
210 [X,Y,Z] = ndgrid(x,y,z);
212 // compute (and display) the linear interpolant on some slices
214 dir = ["z=" "z=" "z=" "x=" "y="];
215 val = [ 0.1 0.5 0.9 0.5 0.5];
216 ebox = [0 1 0 1 0 1];
218 XF=[]; YF=[]; ZF=[]; VF=[];
219 for i = 1:length(val)
220 [Xm,Xp,Ym,Yp,Zm,Zp] = slice_parallelepiped(dir(i), val(i), ebox, m, m, m);
221 Vm = linear_interpn(Xm,Ym,Zm, x, y, z, V);
222 [xf,yf,zf,vf] = nf3dq(Xm,Ym,Zm,Vm,1);
223 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf];
224 Vp = linear_interpn(Xp,Yp,Zp, x, y, z, V);
225 [xf,yf,zf,vf] = nf3dq(Xp,Yp,Zp,Vp,1);
226 XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf];
229 vmin = min(VF); vmax = max(VF);
230 color = dsearch(VF,linspace(vmin,vmax,nb_col+1));
231 xset("colormap",jetcolormap(nb_col));
233 xset("hidden3d",xget("background"))
235 plot3d(XF, YF, list(ZF,color), flag=[-1 6 4])
236 xtitle("tri-linear interpolation of "+func)
240 <refsection role="see also">
242 <simplelist type="inline">
244 <link linkend="interpln">interpln</link>
247 <link linkend="splin">splin</link>
250 <link linkend="splin2d">splin2d</link>
253 <link linkend="splin3d">splin3d</link>