5824
|
1 ## Copyright (C) 2000 Paul Kienzle |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
5831
|
21 ## @deftypefn {Function File} {@var{yi} =} ppval (@var{pp}, @var{xi}) |
5824
|
22 ## Evaluate piece-wise polynomial @var{pp} at the points @var{xi}. |
|
23 ## If @code{@var{pp}.d} is a scalar greater than 1, or an array, |
|
24 ## then the returned value @var{yi} will be an array that is |
|
25 ## @code{d1, d1, @dots{}, dk, length (@var{xi})]}. |
|
26 ## @seealso{mkpp, unmkpp, spline} |
|
27 ## @end deftypefn |
|
28 |
|
29 function yi = ppval (pp, xi) |
|
30 |
|
31 if (nargin != 2) |
|
32 usage ("yi = ppval(pp, xi)") |
|
33 endif |
|
34 if (! isstruct (pp)) |
|
35 error ("ppval: expects a pp structure"); |
|
36 endif |
|
37 if (isempty (xi)) |
|
38 yi = []; |
|
39 else |
|
40 transposed = (columns (xi) == 1); |
|
41 xi = xi(:); |
|
42 xn = length (xi); |
|
43 idx = lookup (pp.x(2:pp.n), xi) + 1; |
|
44 dx = (xi - pp.x(idx))'; |
|
45 dx = reshape (dx(ones(1,prod(pp.d)),:),[pp.d,xn]); |
|
46 c = reshape (pp.P(:,1), pp.n, prod (pp.d)); |
|
47 yi = reshape (c(idx,:)', [pp.d, xn]); |
|
48 for i = 2 : pp.k; |
|
49 c = reshape (pp.P(:,i), pp.n, prod (pp.d)); |
|
50 yi = yi .* dx + reshape (c(idx,:)', [pp.d, xn]); |
|
51 endfor |
|
52 if (transposed && isscalar (pp.d) && pp.d == 1) |
|
53 yi = yi.'; |
|
54 endif |
|
55 endif |
|
56 endfunction |