Mercurial > hg > octave-nkf
annotate scripts/polynomial/mkpp.m @ 12541:dd2c70b30f28
Add tests for ifftshift.m
author | Robert T. Short <octave@phaselockedsystems.com.com> |
---|---|
date | Sat, 26 Mar 2011 06:50:12 -0700 |
parents | c792872f8942 |
children | 59e2460acae1 |
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 -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
20 ## @deftypefn {Function File} {@var{pp} =} mkpp (@var{x}, @var{p}) |
7650 | 21 ## @deftypefnx {Function File} {@var{pp} =} mkpp (@var{x}, @var{p}, @var{d}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
22 ## |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 ## Construct a piecewise polynomial structure from sample points |
8494 | 24 ## @var{x} and coefficients @var{p}. The i-th row of @var{p}, |
5824 | 25 ## @code{@var{p} (@var{i},:)}, contains the coefficients for the polynomial |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
26 ## over the @var{i}-th interval, ordered from highest to |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
27 ## lowest. There must be one row for each interval in @var{x}, so |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
28 ## @code{rows (@var{p}) == length (@var{x}) - 1}. |
5824 | 29 ## |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
30 ## @var{p} may also be a multi-dimensional array, specifying a vector-valued |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
31 ## or array-valued polynomial. The shape is determined by @var{d}. If @var{d} |
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
32 ## is |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
9768
diff
changeset
|
33 ## not given, the default is @code{size (p)(1:end-2)}. If @var{d} is given, the |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
34 ## leading dimensions of @var{p} are reshaped to conform to @var{d}. |
5824 | 35 ## |
36 ## @seealso{unmkpp, ppval, spline} | |
37 ## @end deftypefn | |
38 | |
39 function pp = mkpp (x, P, d) | |
40 if (nargin < 2 || nargin > 3) | |
6046 | 41 print_usage (); |
5824 | 42 endif |
43 pp.x = x(:); | |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
44 n = length (x) - 1; |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
45 if (n < 1) |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
46 error ("mkpp: at least one interval is needed"); |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
47 endif |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
48 nd = ndims (P); |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
49 k = size (P, nd); |
5824 | 50 if (nargin < 3) |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
51 if (nd == 2) |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
52 d = 1; |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
53 else |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
54 d = prod (size (P)(1:nd-1)); |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
55 endif |
5824 | 56 endif |
57 pp.d = d; | |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
58 pp.P = P = reshape (P, prod (d), [], k); |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
59 pp.orient = 0; |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
60 |
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9051
diff
changeset
|
61 if (size (P, 2) != n) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
62 error ("mkpp: num intervals in X doesn't match num polynomials in P"); |
5824 | 63 endif |
64 endfunction | |
65 | |
66 %!demo # linear interpolation | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
67 %! x=linspace(0,pi,5)'; |
5824 | 68 %! t=[sin(x),cos(x)]; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
69 %! m=diff(t)./(x(2)-x(1)); |
5824 | 70 %! b=t(1:4,:); |
71 %! pp = mkpp(x, [m(:),b(:)]); | |
72 %! xi=linspace(0,pi,50); | |
6746 | 73 %! plot(x,t,"x",xi,ppval(pp,xi)); |
74 %! legend("control","interp"); |