Mercurial > octave
annotate scripts/polynomial/ppder.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2008-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
6 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 ## 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
|
8 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 ## (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
|
13 ## |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
14 ## Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 ## 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
|
18 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 ## 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
|
20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
24 ## @deftypefn {} {ppd =} ppder (pp) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
25 ## @deftypefnx {} {ppd =} ppder (pp, m) |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13258
diff
changeset
|
26 ## Compute the piecewise @var{m}-th derivative of a piecewise polynomial |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
27 ## struct @var{pp}. |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
28 ## |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
29 ## 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
|
30 ## @seealso{mkpp, ppval, ppint} |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 ## @end deftypefn |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
33 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
|
34 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
35 if (nargin < 1 || nargin > 2) |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 print_usage (); |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
38 |
13258
be74491c20e8
Correct typo in input validation of polynomial functions (Bug #33252)
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
39 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
|
40 error ("ppder: PP must be a structure"); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 endif |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 [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
|
44 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
45 if (k - m <= 0) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
46 x = [x(1) x(end)]; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
47 pd = zeros (prod (d), 1); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
49 f = k : -1 : 1; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
50 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
|
51 k -= m; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
52 pd = p(:,1:k) * diag (ff(1:k)); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
54 |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 ppd = mkpp (x, pd, d); |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
56 |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 endfunction |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
60 %!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
|
61 %! x = 0:8; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
62 %! 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
|
63 %! pp = spline (x, y); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 %! ppd = ppder (pp); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 %!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
|
66 %!assert (ppd.order, 3) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
67 %! ppd = ppder (pp, 2); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 %!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
|
69 %!assert (ppd.order, 2) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 %! ppd = ppder (pp, 3); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
71 %!assert (ppd.order, 1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 %!assert (ppd.pieces, 8) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
73 %!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
|
74 %! ppd = ppder (pp, 4); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
75 %!assert (ppd.order, 1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 %!assert (ppd.pieces, 1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
77 %!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
|
78 %!assert (ppval (ppd,x), zeros (size (y)), 1e-14) |