annotate scripts/polynomial/ppval.m @ 6046:34f96dd5441b

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