1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
<?xml version="1.0" encoding="UTF-8"?>
<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="interp" xml:lang="en">
<refnamediv>
<refname>interp</refname>
<refpurpose>cubic spline evaluation function</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>[ yp [,yp1 [,yp2 [,yp3]]]] = interp(xp, x, y, d [, out_mode])</synopsis>
</refsynopsisdiv>
<refsection>
<title>Arguments</title>
<variablelist>
<varlistentry>
<term>x,y</term>
<listitem>
<para>
real vectors of same size <literal>n</literal>: Coordinates of data points on which the interpolation and the related cubic spline (called <literal>s(X)</literal> in the following) or sub-spline function is based and built.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>d</term>
<listitem>
<para>real vector of size(x): The derivative s'(x). Most often, s'(x) will be priorly estimated through the function splin(x, y,..)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>out_mode</term>
<listitem>
<para>
(optional) string defining <literal>s(X)</literal> for <literal>X</literal> outside <latex>[x_1,\ x_n]</latex>.
Possible values: "by_zero" | "by_nan" | "C0" | "natural" | "linear" | "periodic"
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>xp</term>
<listitem>
<para>
real vector or matrix: abscissae at which <literal>Y</literal> is unknown and must be estimated with <literal>s(xp)</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>yp</term>
<listitem>
<para>
vector or matrix of size(xp): <literal>yp(i) = s(xp(i))</literal> or <literal>yp(i,j) = s(xp(i,j))</literal>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>yp1, yp2, yp3</term>
<listitem>
<para>
vectors (or matrices) of size(x): elementwise evaluation of the derivatives <literal>s'(xp)</literal>, <literal>s''(xp)</literal> and <literal>s'''(xp)</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
The cubic spline function <literal>s(X)</literal> interpolating the <literal>(x,y)</literal> set of given points is a continuous and derivable piece-wise function defined over <latex>[x_1,\ x_n]</latex>. It consists of a set of cubic polynomials, each one <latex>p_k(X)</latex> being defined on <latex>[x_k,\ x_{k+1}]</latex> and connected in values and slopes to both its neighbours. Thus, we can state that for each <latex>X\ \in\ [x_k,\ x_{k+1}],\ s(X) = p_k(X)</latex>, such that
<latex>s(x_i) = y_i,\quad \mbox{and}\quad s'(x_i) = d_i</latex>. Then, interp() evaluates <literal>s(X)</literal> (and <literal>s'(X), s''(X), s'''(X)</literal> if needed) at <literal>xp(i)</literal>, such that
</para>
<latex style="display" align="center"><![CDATA[ yp_i = s(xp_i) \quad or \quad yp_{i,j} = s(xp_{i,j}) ]]></latex>
<latex style="display" align="center"><![CDATA[ yp1_i = s'(xp_i) \quad or \quad yp1_{i,j} = s'(xp_{i,j}) ]]></latex>
<latex style="display" align="center"><![CDATA[ yp2_i = s''(xp_i) \quad or \quad yp2_{i,j} = s''(xp_{i,j}) ]]></latex>
<latex style="display" align="center"><![CDATA[ yp3_i = s'''(xp_i) \quad or \quad yp3_{i,j} = s'''(xp_{i,j}) ]]></latex>
<para>
The <literal>out_mode</literal> parameter set the evaluation rule
for extrapolation, i.e. for <literal>xp(i)</literal> outside <latex>[x_1,\ x_n]</latex> :
</para>
<variablelist>
<varlistentry>
<term>"by_zero"</term>
<listitem>
<para>an extrapolation by zero is done</para>
</listitem>
</varlistentry>
<varlistentry>
<term>"by_nan"</term>
<listitem>
<para>extrapolation by Nan (%nan)</para>
</listitem>
</varlistentry>
<varlistentry>
<term>"C0"</term>
<listitem>
<para>the extrapolation is defined as follows :</para>
<latex style="display" align="center"><![CDATA[ xp_i < x_1 \Rightarrow yp_i = y_1 ]]></latex>
<latex style="display" align="center"><![CDATA[ xp_i > x_n \Rightarrow yp_i = y_n ]]></latex>
</listitem>
</varlistentry>
<varlistentry>
<term>"natural"</term>
<listitem>
<para>
the extrapolation is defined as follows (<latex>p_i(x)</latex> being the polynomial defining
<literal>s(X)</literal> on <latex>[x_i,\ x_{i+1}]</latex>)
</para>
<latex style="display" align="center"><![CDATA[ xp_i < x_1 \Rightarrow yp_i = p_1(xp_i) ]]></latex>
<latex style="display" align="center"><![CDATA[ xp_i > x_n \Rightarrow yp_i = p_{n-1}(xp_i) ]]></latex>
</listitem>
</varlistentry>
<varlistentry>
<term>"linear"</term>
<listitem>
<para>the extrapolation is defined as follows :</para>
<latex style="display" align="center"><![CDATA[ xp_i < x_1 \Rightarrow yp_i = y_1 + d_1.(xp_i - x_1) ]]></latex>
<latex style="display" align="center"><![CDATA[ xp_i > x_n \Rightarrow yp_i = y_n + d_n.(xp_i - x_n) ]]></latex>
</listitem>
</varlistentry>
<varlistentry>
<term>"periodic"</term>
<listitem>
<para>
<literal>s(X)</literal> is extended by periodicity:
</para>
<latex style="display" align="center"><![CDATA[ yp_i = s( x_1 + ( (xp_i-x_1)\ \mbox{modulo}\ [x_n-x_1] ) ) ]]></latex>
</listitem>
</varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
// see the examples of splin and lsq_splin
// an example showing C2 and C1 continuity of spline and subspline
a = -8; b = 8;
x = linspace(a,b,20)';
y = sinc(x);
dk = splin(x,y); // not_a_knot
df = splin(x,y, "fast");
xx = linspace(a,b,800)';
[yyk, yy1k, yy2k] = interp(xx, x, y, dk);
[yyf, yy1f, yy2f] = interp(xx, x, y, df);
clf()
subplot(3,1,1)
plot2d(xx, [yyk yyf])
plot2d(x, y, style=-9)
legends(["not_a_knot spline","fast sub-spline","interpolation points"],...
[1 2 -9], "ur",%f)
xtitle("spline interpolation")
subplot(3,1,2)
plot2d(xx, [yy1k yy1f])
legends(["not_a_knot spline","fast sub-spline"], [1 2], "ur",%f)
xtitle("spline interpolation (derivatives)")
subplot(3,1,3)
plot2d(xx, [yy2k yy2f])
legends(["not_a_knot spline","fast sub-spline"], [1 2], "lr",%f)
xtitle("spline interpolation (second derivatives)")
]]></programlisting>
<scilab:image>
a = -8; b = 8;
x = linspace(a,b,20)';
y = sinc(x);
dk = splin(x,y); // not_a_knot
df = splin(x,y, "fast");
xx = linspace(a,b,800)';
[yyk, yy1k, yy2k] = interp(xx, x, y, dk);
[yyf, yy1f, yy2f] = interp(xx, x, y, df);
clf()
subplot(3,1,1)
plot2d(xx, [yyk yyf])
plot2d(x, y, style=-9)
legends(["not_a_knot spline","fast sub-spline","interpolation points"],...
[1 2 -9], "ur",%f)
xtitle("spline interpolation")
subplot(3,1,2)
plot2d(xx, [yy1k yy1f])
legends(["not_a_knot spline","fast sub-spline"], [1 2], "ur",%f)
xtitle("spline interpolation (derivatives)")
subplot(3,1,3)
plot2d(xx, [yy2k yy2f])
legends(["not_a_knot spline","fast sub-spline"], [1 2], "lr",%f)
xtitle("spline interpolation (second derivatives)")
</scilab:image>
<programlisting role="example"><![CDATA[
// here is an example showing the different extrapolation possibilities
x = linspace(0,1,11)';
y = cosh(x-0.5);
d = splin(x,y);
xx = linspace(-0.5,1.5,401)';
yy0 = interp(xx,x,y,d,"C0");
yy1 = interp(xx,x,y,d,"linear");
yy2 = interp(xx,x,y,d,"natural");
yy3 = interp(xx,x,y,d,"periodic");
clf()
plot2d(xx,[yy0 yy1 yy2 yy3],style=2:5,frameflag=2,leg="C0@linear@natural@periodic")
xtitle(" different way to evaluate a spline outside its domain")
]]></programlisting>
<scilab:image>
x = linspace(0,1,11)';
y = cosh(x-0.5);
d = splin(x,y);
xx = linspace(-0.5,1.5,401)';
yy0 = interp(xx,x,y,d,"C0");
yy1 = interp(xx,x,y,d,"linear");
yy2 = interp(xx,x,y,d,"natural");
yy3 = interp(xx,x,y,d,"periodic");
clf()
plot2d(xx,[yy0 yy1 yy2 yy3],style=2:5,frameflag=2,leg="C0@linear@natural@periodic")
xtitle(" different way to evaluate a spline outside its domain")
</scilab:image>
</refsection>
<refsection role="see also">
<title>See Also</title>
<simplelist type="inline">
<member>
<link linkend="splin">splin</link>
</member>
<member>
<link linkend="lsq_splin">lsq_splin</link>
</member>
</simplelist>
</refsection>
<refsection>
<title>History</title>
<revhistory>
<revision>
<revnumber>5.4.0</revnumber>
<revremark>previously, imaginary part of input arguments were implicitly ignored.</revremark>
</revision>
</revhistory>
</refsection>
</refentry>
|