Mercurial > hg > octave-nkf
annotate scripts/polynomial/unmkpp.m @ 14383:07c55bceca23 stable
Fix guarded_eval() subfunction in fminunc (bug #35534).
* fminunc.m: Fix guarded_eval() subfunction in fminunc (bug #35534).
author | Olaf Till <olaf.till@uni-jena.de> |
---|---|
date | Wed, 15 Feb 2012 14:44:37 +0100 |
parents | 72c96de7a403 |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
1 ## Copyright (C) 2000-2012 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 -*- | |
20 ## @deftypefn {Function File} {[@var{x}, @var{p}, @var{n}, @var{k}, @var{d}] =} unmkpp (@var{pp}) | |
21 ## | |
11536
702dbd0c53f5
Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 ## Extract the components of a piecewise polynomial structure @var{pp}. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13770
diff
changeset
|
23 ## The components are: |
5824 | 24 ## |
25 ## @table @asis | |
26 ## @item @var{x} | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7017
diff
changeset
|
27 ## Sample points. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9768
diff
changeset
|
28 ## |
5824 | 29 ## @item @var{p} |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## Polynomial coefficients for points in sample interval. @code{@var{p} |
5824 | 31 ## (@var{i}, :)} contains the coefficients for the polynomial over |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
32 ## interval @var{i} ordered from highest to lowest. If @code{@var{d} > |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
33 ## 1}, @code{@var{p} (@var{r}, @var{i}, :)} contains the coefficients for |
9768
31900e17b5f5
improve Matlab compatibility & performance of ppval/mkpp and some associated funcs
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
34 ## the r-th polynomial defined on interval @var{i}. |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9768
diff
changeset
|
35 ## |
5824 | 36 ## @item @var{n} |
37 ## Number of polynomial pieces. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9768
diff
changeset
|
38 ## |
5824 | 39 ## @item @var{k} |
40 ## Order of the polynomial plus 1. | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9768
diff
changeset
|
41 ## |
5824 | 42 ## @item @var{d} |
43 ## Number of polynomials defined for each interval. | |
44 ## @end table | |
45 ## | |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13770
diff
changeset
|
46 ## @seealso{mkpp, ppval, spline, pchip} |
5824 | 47 ## @end deftypefn |
48 | |
49 function [x, P, n, k, d] = unmkpp (pp) | |
13770
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
50 |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
51 if (nargin != 1) |
6046 | 52 print_usage (); |
5824 | 53 endif |
13770
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
54 if (! (isstruct (pp) && isfield (pp, "form") && strcmp (pp.form, "pp"))) |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
55 error ("unmkpp: PP must be a piecewise polynomial structure"); |
5824 | 56 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
57 x = pp.breaks; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
58 P = pp.coefs; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
59 n = pp.pieces; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
60 k = pp.order; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
61 d = pp.dim; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
11587
diff
changeset
|
62 |
5824 | 63 endfunction |
13770
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
64 |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
65 |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
66 %!test |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
67 %! b = 1:3; |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
68 %! c = 1:24; |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
69 %! pp = mkpp (b,c); |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
70 %! [x, P, n, k, d] = unmkpp (pp); |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
71 %! assert (x, b); |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
72 %! assert (P, reshape (c, [2 12])); |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
73 %! assert (n, 2); |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
74 %! assert (k, 12); |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
75 %! assert (d, 1); |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
76 |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
77 %% Test input validation |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
78 %!error unmkpp () |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
79 %!error unmkpp (1,2) |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
80 %!error <piecewise polynomial structure> unmkpp (1) |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
81 %!error <piecewise polynomial structure> unmkpp (struct ("field1", "pp")) |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
82 %!error <piecewise polynomial structure> unmkpp (struct ("form", "not_a_pp")) |
b0bb7bd9e0c8
unmkpp.m: Add functional test. Improve input validation.
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
83 |