~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to man/eng/elementary/linear_interpn.xml

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
 
2
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
 
3
<MAN>
 
4
  <LANGUAGE>eng</LANGUAGE>
 
5
  <TITLE>linear_interpn</TITLE>
 
6
  <TYPE>Scilab Function</TYPE>
 
7
  <DATE>February 2004</DATE>
 
8
  <SHORT_DESCRIPTION name="linear_interpn">n dimensional linear interpolation</SHORT_DESCRIPTION>
 
9
  <CALLING_SEQUENCE>
 
10
    <CALLING_SEQUENCE_ITEM>vp = linear_interpn(xp1,xp2,..,xpn, x1, ..., xn, v [,out_mode])</CALLING_SEQUENCE_ITEM>
 
11
  </CALLING_SEQUENCE>
 
12
  <PARAM>
 
13
    <PARAM_INDENT>
 
14
      <PARAM_ITEM>
 
15
        <PARAM_NAME>xp1, xp2, .., xpn</PARAM_NAME>
 
16
        <PARAM_DESCRIPTION>
 
17
          <SP>: real vectors (or matrices) of same size</SP>
 
18
        </PARAM_DESCRIPTION>
 
19
      </PARAM_ITEM>
 
20
      <PARAM_ITEM>
 
21
        <PARAM_NAME>x1 ,x2, ..., xn</PARAM_NAME>
 
22
        <PARAM_DESCRIPTION>
 
23
          <SP>:  strictly increasing row vectors (with at least 2 components)
 
24
               defining the n dimensional interpolation grid</SP>
 
25
        </PARAM_DESCRIPTION>
 
26
      </PARAM_ITEM>
 
27
      <PARAM_ITEM>
 
28
        <PARAM_NAME>v</PARAM_NAME>
 
29
        <PARAM_DESCRIPTION>
 
30
          <SP>:  vector (case n=1), matrix (case n=2) or hypermatrix (case n &gt; 2) with the
 
31
                 values of the underlying interpolated function at the grid points.</SP>
 
32
        </PARAM_DESCRIPTION>
 
33
      </PARAM_ITEM>
 
34
      <PARAM_ITEM>
 
35
        <PARAM_NAME>out_mode</PARAM_NAME>
 
36
        <PARAM_DESCRIPTION>
 
37
          <SP>: (optionnal) string defining the evaluation outside the grid (extrapolation)</SP>
 
38
        </PARAM_DESCRIPTION>
 
39
      </PARAM_ITEM>
 
40
      <PARAM_ITEM>
 
41
        <PARAM_NAME>vp</PARAM_NAME>
 
42
        <PARAM_DESCRIPTION>
 
43
          <SP>:  vector or matrix of same size than <VERB>xp1, ..., xpn</VERB></SP>
 
44
        </PARAM_DESCRIPTION>
 
45
      </PARAM_ITEM>
 
46
    </PARAM_INDENT>
 
47
  </PARAM>
 
48
  <DESCRIPTION>
 
49
    <P>
 
50
    Given a n dimensional grid defined by the n vectors <VERB>x1 ,x2, ..., xn</VERB> and the
 
51
    values <VERB>v</VERB> of a function (says <EM>f</EM>) at the grid points :
 
52
    </P>
 
53
        <VERBATIM><![CDATA[
 
54
      v(i1,i2,...,in) = f(x1(i1),x2(i2), ..., xn(in))
 
55
         ]]></VERBATIM>
 
56
    <P>
 
57
    this function computes the linear interpolant of <EM>f</EM> from the grid (called <EM>s</EM>
 
58
    in the following) at the points which coordinates are defined by the vectors (or matrices) 
 
59
    <VERB>xp1, xp2, ..., xpn</VERB>:
 
60
    </P>
 
61
        <VERBATIM><![CDATA[
 
62
   vp(i) = s(xp1(i),xp2(i), ..., xpn(i))
 
63
 
 
64
   or vp(i,j) = s(xp1(i,j),xp2(i,j), ..., xpn(i,j)) in case the xpk are matrices
 
65
         ]]></VERBATIM>
 
66
    <P>
 
67
    The <VERB>out_mode</VERB> parameter set the evaluation rule for extrapolation: if we note 
 
68
    <EM>Pi=(xp1(i),xp2(i),...,xpn(i))</EM> then <VERB>out_mode</VERB> defines the
 
69
    evaluation rule when:
 
70
    </P>
 
71
        <VERBATIM><![CDATA[
 
72
   P(i) not in  [x1(1) x1($)] x [x2(1) x2($)] x ... x [xn(1) xn($)]
 
73
         ]]></VERBATIM>
 
74
    <P>
 
75
    The different choices are:
 
76
    </P>
 
77
    <ITEMIZE label="out_mode">
 
78
      <ITEM label="&quot;by_zero&quot;">
 
79
         <SP>: an extrapolation by zero is done</SP>
 
80
      </ITEM>
 
81
      <ITEM label="&quot;by_nan&quot;">
 
82
         <SP>: extrapolation by Nan</SP>
 
83
      </ITEM>
 
84
      <ITEM label="&quot;C0&quot;">
 
85
         <SP>: the extrapolation is defined as follows:</SP>
 
86
        <VERBATIM><![CDATA[
 
87
     s(P) = s(proj(P)) where proj(P) is nearest point from P 
 
88
                       located on the grid boundary.
 
89
         ]]></VERBATIM>
 
90
      </ITEM>
 
91
      <ITEM label="&quot;natural&quot;">
 
92
         <SP>: the extrapolation is done by using the nearest n-linear patch from the point.</SP>
 
93
      </ITEM>
 
94
      <ITEM label="&quot;periodic&quot;">
 
95
         <SP>: <VERB>s</VERB> is extended by periodicity.</SP>
 
96
      </ITEM>
 
97
    </ITEMIZE>
 
98
  </DESCRIPTION>
 
99
 
 
100
  <EXAMPLE><![CDATA[
 
101
// example 1 : 1d linear interpolation
 
102
x = linspace(0,2*%pi,11);
 
103
y = sin(x);
 
104
xx = linspace(-2*%pi,4*%pi,400)';
 
105
yy = linear_interpn(xx, x, y, "periodic");
 
106
xbasc()
 
107
plot2d(xx,yy,style=2)
 
108
plot2d(x,y,style=-9, strf="000")
 
109
xtitle("linear interpolation of sin(x) with 11 interpolation points")
 
110
 
 
111
// example 2 : bilinear interpolation
 
112
n = 8;
 
113
x = linspace(0,2*%pi,n); y = x;
 
114
z = 2*sin(x')*sin(y);
 
115
xx = linspace(0,2*%pi, 40);
 
116
[xp,yp] = ndgrid(xx,xx);
 
117
zp = linear_interpn(xp,yp, x, y, z);
 
118
xbasc()
 
119
plot3d(xx, xx, zp, flag=[2 6 4])
 
120
[xg,yg] = ndgrid(x,x);
 
121
param3d1(xg,yg, list(z,-9*ones(1,n)), flag=[0 0])
 
122
xtitle("Bilinear interpolation of 2sin(x)sin(y)")
 
123
legends("interpolation points",-9,1)
 
124
xselect()
 
125
 
 
126
// example 3 : bilinear interpolation and experimentation
 
127
//             with all the outmode features
 
128
nx = 20; ny = 30;
 
129
x = linspace(0,1,nx);
 
130
y = linspace(0,2, ny);
 
131
[X,Y] = ndgrid(x,y);
 
132
z = 0.4*cos(2*%pi*X).*cos(%pi*Y);
 
133
nxp = 60 ; nyp = 120;
 
134
xp = linspace(-0.5,1.5, nxp);
 
135
yp = linspace(-0.5,2.5, nyp);
 
136
[XP,YP] = ndgrid(xp,yp);
 
137
zp1 = linear_interpn(XP, YP, x, y, z, "natural");
 
138
zp2 = linear_interpn(XP, YP, x, y, z, "periodic");
 
139
zp3 = linear_interpn(XP, YP, x, y, z, "C0");
 
140
zp4 = linear_interpn(XP, YP, x, y, z, "by_zero");
 
141
zp5 = linear_interpn(XP, YP, x, y, z, "by_nan");
 
142
xbasc()
 
143
subplot(2,3,1)
 
144
   plot3d(x, y, z, leg="x@y@z", flag = [2 4 4])
 
145
   xtitle("initial function 0.4 cos(2 pi x) cos(pi y)")
 
146
subplot(2,3,2)
 
147
   plot3d(xp, yp, zp1, leg="x@y@z", flag = [2 4 4])
 
148
   xtitle("Natural")
 
149
subplot(2,3,3)
 
150
   plot3d(xp, yp, zp2, leg="x@y@z", flag = [2 4 4])
 
151
   xtitle("Periodic")
 
152
subplot(2,3,4)
 
153
   plot3d(xp, yp, zp3, leg="x@y@z", flag = [2 4 4])
 
154
   xtitle("C0")
 
155
subplot(2,3,5)
 
156
   plot3d(xp, yp, zp4, leg="x@y@z", flag = [2 4 4])
 
157
   xtitle("by_zero")
 
158
subplot(2,3,6)
 
159
   plot3d(xp, yp, zp5, leg="x@y@z", flag = [2 4 4])
 
160
   xtitle("by_nan")
 
161
xselect()
 
162
 
 
163
 
 
164
// example 4 : trilinear interpolation (see splin3d help
 
165
//             page which have the same example with
 
166
//             tricubic spline interpolation)
 
167
getf("SCI/demos/interp/interp_demo.sci") 
 
168
func =  "v=(x-0.5).^2 + (y-0.5).^3 + (z-0.5).^2";
 
169
deff("v=f(x,y,z)",func);
 
170
n = 5; 
 
171
x = linspace(0,1,n); y=x; z=x;
 
172
[X,Y,Z] = ndgrid(x,y,z);
 
173
V = f(X,Y,Z);
 
174
// compute (and display) the linear interpolant on some slices
 
175
m = 41;
 
176
dir = ["z="  "z="  "z="  "x="  "y="];
 
177
val = [ 0.1   0.5   0.9   0.5   0.5];
 
178
ebox = [0 1 0 1 0 1];
 
179
 
 
180
XF=[]; YF=[]; ZF=[]; VF=[];
 
181
for i = 1:length(val)
 
182
   [Xm,Xp,Ym,Yp,Zm,Zp] = slice_parallelepiped(dir(i), val(i), ebox, m, m, m);
 
183
   Vm = linear_interpn(Xm,Ym,Zm, x, y, z, V);
 
184
   [xf,yf,zf,vf] = nf3dq(Xm,Ym,Zm,Vm,1);
 
185
   XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
 
186
   Vp =  linear_interpn(Xp,Yp,Zp, x, y, z, V);
 
187
   [xf,yf,zf,vf] = nf3dq(Xp,Yp,Zp,Vp,1);
 
188
   XF = [XF xf]; YF = [YF yf]; ZF = [ZF zf]; VF = [VF vf]; 
 
189
end
 
190
nb_col = 128;
 
191
vmin = min(VF); vmax = max(VF);
 
192
color = dsearch(VF,linspace(vmin,vmax,nb_col+1));
 
193
xset("colormap",jetcolormap(nb_col));
 
194
xbasc()
 
195
xset("hidden3d",xget("background"))
 
196
colorbar(vmin,vmax)
 
197
plot3d(XF, YF, list(ZF,color), flag=[-1 6 4])
 
198
xtitle("tri-linear interpolation of "+func)
 
199
xselect()
 
200
 ]]></EXAMPLE>
 
201
 
 
202
  <SEE_ALSO>
 
203
    <SEE_ALSO_ITEM>
 
204
      <LINK>interpln</LINK>
 
205
    </SEE_ALSO_ITEM>
 
206
    <SEE_ALSO_ITEM>
 
207
      <LINK>splin</LINK>
 
208
    </SEE_ALSO_ITEM>
 
209
    <SEE_ALSO_ITEM>
 
210
      <LINK>splin2d</LINK>
 
211
    </SEE_ALSO_ITEM>
 
212
    <SEE_ALSO_ITEM>
 
213
      <LINK>splin3d</LINK>
 
214
    </SEE_ALSO_ITEM>
 
215
  </SEE_ALSO>
 
216
  <AUTHOR>
 
217
    B. Pincon
 
218
  </AUTHOR>
 
219
</MAN>