7017
|
1 ## Copyright (C) 2000, 2006, 2007 Paul Kienzle |
5824
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
5824
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
5824
|
18 |
|
19 ## -*- texinfo -*- |
5831
|
20 ## @deftypefn {Function File} {@var{yi} =} ppval (@var{pp}, @var{xi}) |
5824
|
21 ## Evaluate piece-wise polynomial @var{pp} at the points @var{xi}. |
|
22 ## If @code{@var{pp}.d} is a scalar greater than 1, or an array, |
|
23 ## then the returned value @var{yi} will be an array that is |
|
24 ## @code{d1, d1, @dots{}, dk, length (@var{xi})]}. |
|
25 ## @seealso{mkpp, unmkpp, spline} |
|
26 ## @end deftypefn |
|
27 |
|
28 function yi = ppval (pp, xi) |
|
29 |
|
30 if (nargin != 2) |
6046
|
31 print_usage (); |
5824
|
32 endif |
|
33 if (! isstruct (pp)) |
|
34 error ("ppval: expects a pp structure"); |
|
35 endif |
|
36 if (isempty (xi)) |
|
37 yi = []; |
|
38 else |
|
39 transposed = (columns (xi) == 1); |
|
40 xi = xi(:); |
|
41 xn = length (xi); |
|
42 idx = lookup (pp.x(2:pp.n), xi) + 1; |
6014
|
43 dx = (xi - pp.x(idx)).'; |
5824
|
44 dx = reshape (dx(ones(1,prod(pp.d)),:),[pp.d,xn]); |
|
45 c = reshape (pp.P(:,1), pp.n, prod (pp.d)); |
6014
|
46 yi = reshape (c(idx,:).', [pp.d, xn]); |
5824
|
47 for i = 2 : pp.k; |
|
48 c = reshape (pp.P(:,i), pp.n, prod (pp.d)); |
6014
|
49 yi = yi .* dx + reshape (c(idx,:).', [pp.d, xn]); |
5824
|
50 endfor |
|
51 if (transposed && isscalar (pp.d) && pp.d == 1) |
|
52 yi = yi.'; |
|
53 endif |
|
54 endif |
|
55 endfunction |