annotate scripts/polynomial/ppder.m @ 19833:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children f1d0f506ee78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17795
diff changeset
1 ## Copyright (C) 2008-2015 VZLU Prague, a.s., Czech Republic
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
2 ##
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
3 ## This file is part of Octave.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
4 ##
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published by
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 ## (at your option) any later version.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
9 ##
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 ## This program is distributed in the hope that it will be useful,
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ## GNU General Public License for more details.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
14 ##
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
17795
0a8c35ae5ce1 maint: Fix various problems with GPL copyright statements.
Rik <rik@octave.org>
parents: 17744
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 ## -*- texinfo -*-
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
20 ## @deftypefn {Function File} {ppd =} ppder (pp)
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
21 ## @deftypefnx {Function File} {ppd =} ppder (pp, m)
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13258
diff changeset
22 ## Compute the piecewise @var{m}-th derivative of a piecewise polynomial
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
23 ## struct @var{pp}. If @var{m} is omitted the first derivative is calculated.
12575
d0b799dafede Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
24 ## @seealso{mkpp, ppval, ppint}
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25 ## @end deftypefn
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
27 function ppd = ppder (pp, m = 1)
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
28
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 if (nargin < 1 || nargin > 2)
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 print_usage ();
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 endif
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
32
13258
be74491c20e8 Correct typo in input validation of polynomial functions (Bug #33252)
Rik <octave@nomad.inbox5.com>
parents: 12608
diff changeset
33 if (! (isstruct (pp) && strcmp (pp.form, "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: 10793
diff changeset
34 error ("ppder: PP must be a structure");
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 endif
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37 [x, p, n, k, d] = unmkpp (pp);
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
38
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
39 if (k - m <= 0)
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
40 x = [x(1) x(end)];
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
41 pd = zeros (prod (d), 1);
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 else
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
43 f = k : -1 : 1;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
44 ff = bincoeff (f, m + 1) .* factorial (m + 1) ./ f;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
45 k -= m;
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
46 pd = p(:,1:k) * diag (ff(1:k));
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
47 endif
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
48
9976
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
49 ppd = mkpp (x, pd, d);
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50 endfunction
702b998698ea implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
52
12608
59e2460acae1 make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents: 12575
diff changeset
53 %!shared x,y,pp,ppd
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
54 %! x = 0:8;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
55 %! y = [x.^2; x.^3+1];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56 %! pp = spline (x, y);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 %! ppd = ppder (pp);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
58 %!assert (ppval (ppd, x), [2*x; 3*x.^2], 1e-14)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59 %!assert (ppd.order, 3)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
60 %! ppd = ppder (pp, 2);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 %!assert (ppval (ppd, x), [2*ones(size (x)); 6*x], 1e-14)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62 %!assert (ppd.order, 2)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63 %! ppd = ppder (pp, 3);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
64 %!assert (ppd.order, 1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
65 %!assert (ppd.pieces, 8)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
66 %!assert (size (ppd.coefs), [16, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
67 %! ppd = ppder (pp, 4);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
68 %!assert (ppd.order, 1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 %!assert (ppd.pieces, 1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 %!assert (size (ppd.coefs), [2, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
71 %!assert (ppval (ppd,x), zeros (size (y)), 1e-14)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
72