Mercurial > octave
annotate scripts/polynomial/polyder.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) 1994-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 ## |
2313 | 6 ## |
7 ## This file is part of Octave. | |
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 |
2313 | 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 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
2313 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
2313 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 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/>. |
1597 | 22 |
3458 | 23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
24 ## @deftypefn {} {} polyder (@var{p}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
25 ## @deftypefnx {} {[@var{k}] =} polyder (@var{a}, @var{b}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20231
diff
changeset
|
26 ## @deftypefnx {} {[@var{q}, @var{d}] =} polyder (@var{b}, @var{a}) |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
27 ## Return the coefficients of the derivative of the polynomial whose |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
28 ## coefficients are given by the vector @var{p}. |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 ## |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
30 ## If a pair of polynomials is given, return the derivative of the product |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## @math{@var{a}*@var{b}}. |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
32 ## |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
33 ## If two inputs and two outputs are given, return the derivative of the |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
34 ## polynomial quotient @math{@var{b}/@var{a}}. The quotient numerator is |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
35 ## in @var{q} and the denominator in @var{d}. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
12803
diff
changeset
|
36 ## @seealso{polyint, polyval, polyreduce} |
3458 | 37 ## @end deftypefn |
1597 | 38 |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
39 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 ## Created: June 1994 |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 ## Adapted-By: jwe |
2314 | 42 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
43 function [q, d] = polyder (p, a) |
1597 | 44 |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 if (nargin == 1 || nargin == 2) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 if (! isvector (p)) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
47 error ("polyder: argument must be a vector"); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
48 endif |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
49 if (nargin == 2) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
50 if (! isvector (a)) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
51 error ("polyder: argument must be a vector"); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
52 endif |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
53 if (nargout == 1) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
54 ## derivative of p*a returns a single polynomial |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
55 q = polyder (conv (p, a)); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
56 else |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
57 ## derivative of p/a returns numerator and denominator |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
58 d = conv (a, a); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
59 if (numel (p) == 1) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
60 q = -p * polyder (a); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
61 elseif (numel (a) == 1) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
62 q = a * polyder (p); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
63 else |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
64 q = conv (polyder (p), a) - conv (p, polyder (a)); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
65 q = polyreduce (q); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
66 endif |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
67 |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
68 ## remove common factors from numerator and denominator |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
69 x = polygcd (q, d); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
70 if (length (x) != 1) |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
71 q = deconv (q, x); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
72 d = deconv (d, x); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
73 endif |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
74 |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
75 ## move all the gain into the numerator |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
76 q /= d(1); |
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
77 d /= d(1); |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
78 endif |
5216 | 79 else |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
80 lp = numel (p); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
81 if (lp == 1) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
82 q = 0; |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
83 return; |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
84 elseif (lp == 0) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
85 q = []; |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
86 return; |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
87 endif |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
88 |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
89 ## Force P to be a row vector. |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
90 p = p(:).'; |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
91 |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
92 q = p(1:(lp-1)) .* [(lp-1):-1:1]; |
5216 | 93 endif |
1597 | 94 else |
6046 | 95 print_usage (); |
1597 | 96 endif |
97 | |
98 endfunction | |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
99 |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
100 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
101 %!assert (polyder ([1, 2, 3], [2, 2])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
102 %!assert (polyder (13), 0) |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
103 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
104 %!error polyder ([]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 %!error polyder (1,2,3) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 %!error <argument must be a vector> polyder ([1, 2; 3, 4]) |