Mercurial > hg > octave-lyh
annotate scripts/polynomial/ppval.m @ 11124:e79f59d31a74
Add tests for fftconv.m
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 20 Oct 2010 21:01:24 -0700 |
parents | a4f482e66b65 |
children | 1740012184f9 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2000, 2006, 2007, 2008 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}. |
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 | 30 ## @seealso{mkpp, unmkpp, spline} |
31 ## @end deftypefn | |
32 | |
33 function yi = ppval (pp, xi) | |
34 | |
35 if (nargin != 2) | |
6046 | 36 print_usage (); |
5824 | 37 endif |
38 if (! isstruct (pp)) | |
39 error ("ppval: expects a pp structure"); | |
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 | 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 | 82 endfunction |