annotate scripts/polynomial/ppval.m @ 12174:db1f49eaba6b

whitespace fixes
author John W. Eaton <jwe@octave.org>
date Wed, 26 Jan 2011 23:49:42 -0500
parents c792872f8942
children 59e2460acae1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
1 ## Copyright (C) 2000-2011 Paul Kienzle
5824
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
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
5824
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
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
18
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
5831
b0d4ff99a0c5 [project @ 2006-05-26 21:06:00 by jwe]
jwe
parents: 5824
diff changeset
20 ## @deftypefn {Function File} {@var{yi} =} ppval (@var{pp}, @var{xi})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
21 ## Evaluate piecewise polynomial @var{pp} at the points @var{xi}.
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
22 ## If @var{pp} is scalar-valued, the result is an array of the same shape as
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
23 ## @var{xi}.
9768
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
24 ## Otherwise, the size of the result is @code{[pp.d, length(@var{xi})]} if
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
25 ## @var{xi} is a vector, or @code{[pp.d, size(@var{xi})]} if it is a
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
26 ## multi-dimensional array. If pp.orient is 1, the dimensions are permuted as
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
27 ## in interp1, to
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
28 ## @code{[pp.d, length(@var{xi})]} and @code{[pp.d, size(@var{xi})]}
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
29 ## respectively.
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
30 ## @seealso{mkpp, unmkpp, spline}
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
31 ## @end deftypefn
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
32
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
33 function yi = ppval (pp, xi)
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
34
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
35 if (nargin != 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 6014
diff changeset
36 print_usage ();
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
37 endif
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
38 if (! isstruct (pp))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
39 error ("ppval: PP must be a structure");
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
40 endif
9768
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
41
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
42 ## Extract info.
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
43 x = pp.x;
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
44 P = pp.P;
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
45 d = pp.d;
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
46 k = size (P, 3);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
47 nd = size (P, 1);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
48
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
49 ## Determine resulting shape.
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
50 if (d == 1) # scalar case
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
51 yisz = size (xi);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
52 elseif (isvector (xi)) # this is special
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
53 yisz = [d, length(xi)];
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
54 else # general
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
55 yisz = [d, size(xi)];
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
56 endif
9768
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
57
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
58 ## Determine intervals.
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
59 xi = xi(:);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
60 xn = numel (xi);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
61
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
62 idx = lookup (x, xi, "lr");
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
63
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
64 ## Offsets.
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
65 dx = (xi - x(idx)).';
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
66 dx = dx(ones (1, nd), :); # spread (do nothing in 1D)
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
67
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
68 ## Use Horner scheme.
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
69 yi = P(:,idx,1);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
70 for i = 2:k;
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
71 yi .*= dx;
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
72 yi += P(:,idx,i);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
73 endfor
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
74
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
75 ## Adjust shape.
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
76 yi = reshape (yi, yisz);
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
77 if (d != 1 && pp.orient == 1)
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
78 ## Switch dimensions to match interp1 order.
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
79 yi = shiftdim (yi, length (d));
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
80 endif
31900e17b5f5 improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
81
5824
448f9982e7fb [project @ 2006-05-19 06:53:31 by jwe]
jwe
parents:
diff changeset
82 endfunction