comparison main/splines/ppval.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 2000 Paul Kienzle
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 ## usage: yi = ppval(pp, xi)
18 ## Evaluate piece-wise polynomial pp and points xi. If pp.d > 1,
19 ## the returned yi will be a matrix of size rows(xi) by pp.d, or
20 ## its transpose if xi is a row vector.
21
22 function yi = ppval(pp, xi)
23 if nargin != 2
24 usage("yi = ppval(pp, xi)")
25 endif
26 if !isstruct(pp)
27 error("ppval: expects a pp structure");
28 endif
29 if (isempty (xi))
30 yi = [];
31 else
32 transposed = (rows(xi) == 1);
33 [nr, nc] = size(xi);
34 xi = xi(:);
35 idx = lookup(pp.x(2:pp.n), xi) + 1;
36 dx = xi - pp.x(idx);
37 dx = dx(:,ones(1,pp.d));
38 c = reshape (pp.P(:, 1), pp.n, pp.d);
39 yi = c(idx, :);
40 for i = 2 : pp.k;
41 c = reshape (pp.P(:, i), pp.n, pp.d);
42 yi = yi .* dx + c(idx, :);
43 endfor
44 if (transposed)
45 yi = yi.';
46 endif
47 endif
48 endfunction