Mercurial > hg > octave-lyh
annotate scripts/polynomial/ppval.m @ 13141:e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
* bicg.m, gmres.m, pkg.m: Untabify and remove trailing whitespace.
* libcruft/Makefile.am, libcruft/blas-xtra/cdotc3.f,
libcruft/blas-xtra/cmatm3.f, libcruft/blas-xtra/ddot3.f,
libcruft/blas-xtra/dmatm3.f, libcruft/blas-xtra/sdot3.f,
libcruft/blas-xtra/smatm3.f, libcruft/blas-xtra/zdotc3.f,
libcruft/blas-xtra/zmatm3.f, libcruft/lapack-xtra/crsf2csf.f,
libcruft/lapack-xtra/zrsf2csf.f, liboctave/Array.cc,
liboctave/DASPK-opts.in, liboctave/DASRT-opts.in,
liboctave/DASSL-opts.in, liboctave/LSODE-opts.in,
liboctave/Makefile.a,mliboctave/Quad-opts.in,
liboctave/Sparse-perm-op-defs.h,
scripts/Makefile.a,mscripts/deprecated/glpkmex.m,
scripts/general/blkdiag.m, scripts/general/interp1.m,
scripts/general/profshow.m, scripts/general/quadl.m,
scripts/general/triplequad.m, scripts/help/__makeinfo__.m,
scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m,
scripts/linear-algebra/rank.m, scripts/miscellaneous/gzip.m,
scripts/miscellaneous/private/__xzip__.m,
scripts/miscellaneous/tempdir.m, scripts/miscellaneous/unpack.m,
scripts/pkg/pkg.m, scripts/plot/allchild.m, scripts/plot/ancestor.m,
scripts/plot/cla.m, scripts/plot/clf.m, scripts/plot/findall.m,
scripts/plot/findobj.m, scripts/plot/gca.m, scripts/plot/gcf.m,
scripts/plot/hggroup.m, scripts/plot/isfigure.m,
scripts/plot/ishghandle.m, scripts/plot/legend.m,
scripts/plot/line.m, scripts/plot/loglog.m, scripts/plot/patch.m,
scripts/plot/print.m, scripts/plot/private/__quiver__.m,
scripts/plot/private/__scatter__.m, scripts/plot/rectangle.m,
scripts/plot/semilogx.m, scripts/plot/semilogy.m,
scripts/plot/surface.m, scripts/plot/text.m, scripts/plot/title.m,
scripts/plot/trisurf.m, scripts/plot/view.m, scripts/plot/whitebg.m,
scripts/plot/xlabel.m, scripts/plot/xlim.m, scripts/plot/ylabel.m,
scripts/plot/ylim.m, scripts/plot/zlabel.m, scripts/plot/zlim.m,
scripts/polynomial/mkpp.m, scripts/polynomial/polygcd.m,
scripts/polynomial/ppint.m, scripts/polynomial/ppjumps.m,
scripts/polynomial/ppval.m, scripts/set/setxor.m,
scripts/sparse/bicgstab.m, scripts/sparse/cgs.m,
scripts/sparse/spconvert.m, scripts/specfun/nthroot.m,
scripts/strings/strmatch.m, scripts/strings/untabify.m,
scripts/testfun/demo.m, scripts/testfun/example.m,
src/DLD-FUNCTIONS/filter.cc, src/DLD-FUNCTIONS/mgorth.cc,
src/DLD-FUNCTIONS/quadcc.cc, src/DLD-FUNCTIONS/str2double.cc,
src/Makefile.a,msrc/gl-render.cc, src/gl2ps-renderer.cc,
src/graphics.cc, src/octave-config.cc.in, src/octave-config.in,
src/ov-class.h, src/ov-fcn.h, src/profiler.cc, src/profiler.h,
src/pt-binop.cc, src/pt-unop.cc, src/symtab.cc, src/txt-eng-ft.cc:
Remove trailing whitespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 15 Sep 2011 12:51:10 -0400 |
parents | 59e2460acae1 |
children | 9b8e786bbf3c |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2000-2011 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}) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
21 ## Evaluate piece-wise polynomial structure @var{pp} at the points @var{xi}. |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
22 ## If @var{pp} describes a scalar polynomial function, the result is an |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
23 ## array of the same shape as @var{xi}. |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
24 ## Otherwise, the size of the result is @code{[pp.dim, length(@var{xi})]} if |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
25 ## @var{xi} is a vector, or @code{[pp.dim, size(@var{xi})]} if it is a |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
26 ## multi-dimensional array. |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
27 ## |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
28 ##, the dimensions are permuted as |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
29 ## in interp1, to |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
30 ## @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
|
31 ## respectively. |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
32 ## @seealso{mkpp, unmkpp, spline, pchip, interp1} |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
33 ## @end deftypefn |
5824 | 34 |
35 function yi = ppval (pp, xi) | |
36 | |
37 if (nargin != 2) | |
6046 | 38 print_usage (); |
5824 | 39 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
40 if (! isstruct (pp) && strcmp (pp.form, "pp")) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
41 error ("ppval: expects a pp-form structure"); |
5824 | 42 endif |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
43 |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
44 ## Extract info. |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
45 [x, P, n, k, d] = unmkpp (pp); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
46 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
47 ## dimension checks |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
48 sxi = size (xi); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
49 if (isvector (xi)) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
50 xi = xi(:).'; |
5824 | 51 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
52 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
53 nd = length (d); |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
54 |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
55 ## Determine intervals. |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
56 xn = numel (xi); |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
57 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
|
58 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
59 P = reshape (P, [d, n * k]); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
60 P = shiftdim (P, nd); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
61 P = reshape (P, [n, k, d]); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
62 Pidx = P(idx(:), :);#2d matrix size x: coefs*prod(d) y: prod(sxi) |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
63 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
64 if (isvector(xi)) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
65 Pidx = reshape (Pidx, [xn, k, d]); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
66 Pidx = shiftdim (Pidx, 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
67 dimvec = [d, xn]; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
68 else |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
69 Pidx = reshape (Pidx, [sxi, k, d]); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
70 Pidx = shiftdim (Pidx, length (sxi)); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
71 dimvec = [d, sxi]; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
72 end |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
73 ndv = length (dimvec); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
74 |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
75 ## Offsets. |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
76 dx = (xi - x(idx)); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
77 dx = repmat (dx, [prod(d), 1]); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
78 dx = reshape (dx, dimvec); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
79 dx = shiftdim (dx, ndv - 1); |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
80 |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
81 ## Use Horner scheme. |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
82 yi = Pidx; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
83 if (k > 1) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
84 yi = shiftdim (reshape (Pidx(1,:), dimvec), ndv - 1); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
85 endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
86 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
87 for i = 2 : k; |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
88 yi .*= dx; |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
89 yi += shiftdim (reshape (Pidx(i,:), dimvec), ndv - 1); |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
90 endfor |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
91 |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
92 ## Adjust shape. |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
93 if ((numel (xi) > 1) || (length (d) == 1)) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
94 yi = reshape (shiftdim (yi, 1), dimvec); |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
95 endif |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
96 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
97 if (isvector (xi) && (d == 1)) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
98 yi = reshape (yi, sxi); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
99 elseif (isfield (pp, "orient") && strcmp (pp.orient, "first")) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
100 yi = shiftdim(yi, nd); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
101 endif |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
102 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
103 ## |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
104 #if (d == 1) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
105 # yi = reshape (yi, sxi); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
106 #endif |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12608
diff
changeset
|
107 |
5824 | 108 endfunction |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
109 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
110 %!shared b,c,pp,pp2,xi,abserr |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
111 %! b = 1:3; c = ones(2); pp=mkpp(b,c);abserr = 1e-14;pp2=mkpp(b,[c;c],2); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
112 %! xi = [1.1 1.3 1.9 2.1]; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
113 %!assert (ppval(pp,1.1), 1.1, abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
114 %!assert (ppval(pp,2.1), 1.1, abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
115 %!assert (ppval(pp,xi), [1.1 1.3 1.9 1.1], abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
116 %!assert (ppval(pp,xi.'), [1.1 1.3 1.9 1.1].', abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
117 %!assert (ppval(pp2,1.1), [1.1;1.1], abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
118 %!assert (ppval(pp2,2.1), [1.1;1.1], abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
119 %!assert (ppval(pp2,xi), [1.1 1.3 1.9 1.1;1.1 1.3 1.9 1.1], abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
120 %!assert (ppval(pp2,xi'), [1.1 1.3 1.9 1.1;1.1 1.3 1.9 1.1], abserr); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
121 %!assert (size(ppval(pp2,[xi;xi])), [2 2 4]); |