Mercurial > hg > octave-lyh
annotate scripts/deprecated/polyderiv.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 1c89599167a6 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12803
diff
changeset
|
1 ## Copyright (C) 1994-2012 John W. Eaton |
2313 | 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. | |
2313 | 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/>. | |
904 | 18 |
3368 | 19 ## -*- texinfo -*- |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
20 ## @deftypefn {Function File} {} polyderiv (@var{p}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
21 ## @deftypefnx {Function File} {[@var{k}] =} polyderiv (@var{a}, @var{b}) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyderiv (@var{b}, @var{a}) |
3368 | 23 ## Return the coefficients of the derivative of the polynomial whose |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
24 ## coefficients are given by the vector @var{p}. If a pair of polynomials |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
25 ## is given, return the derivative of the product @math{@var{a}*@var{b}}. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
26 ## If two inputs and two outputs are given, return the derivative of the |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## polynomial quotient @math{@var{b}/@var{a}}. The quotient numerator is |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
28 ## in @var{q} and the denominator in @var{d}. |
10224
f6e0404421f4
point to polyint in @seealso, not polyinteg
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 ## @seealso{poly, polyint, polyreduce, roots, conv, deconv, residue, |
5642 | 30 ## filter, polygcd, polyval, polyvalm} |
3368 | 31 ## @end deftypefn |
1025 | 32 |
3202 | 33 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 34 ## Created: June 1994 |
35 ## Adapted-By: jwe | |
561 | 36 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
37 function [q, d] = polyderiv (p, a) |
5216 | 38 |
12803
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
39 persistent warned = false; |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
40 if (! warned) |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
41 warned = true; |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
42 warning ("Octave:deprecated-function", |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
43 "polyderiv is obsolete and will be removed from a future version of Octave; please use polyder instead"); |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
44 endif |
b7a6a3644f3b
codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
45 |
5217 | 46 if (nargin == 1 || nargin == 2) |
47 if (! isvector (p)) | |
5216 | 48 error ("polyderiv: argument must be a vector"); |
49 endif | |
5217 | 50 if (nargin == 2) |
51 if (! isvector (a)) | |
10549 | 52 error ("polyderiv: argument must be a vector"); |
5217 | 53 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
54 if (nargout == 1) |
10549 | 55 ## derivative of p*a returns a single polynomial |
56 q = polyderiv (conv (p, a)); | |
5217 | 57 else |
10549 | 58 ## derivative of p/a returns numerator and denominator |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
59 d = conv (a, a); |
10549 | 60 if (numel (p) == 1) |
61 q = -p * polyderiv (a); | |
62 elseif (numel (a) == 1) | |
63 q = a * polyderiv (p); | |
64 else | |
65 q = conv (polyderiv (p), a) - conv (p, polyderiv (a)); | |
66 q = polyreduce (q); | |
67 endif | |
5217 | 68 |
10549 | 69 ## remove common factors from numerator and denominator |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
70 x = polygcd (q, d); |
10549 | 71 if (length(x) != 1) |
72 q = deconv (q, x); | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
73 d = deconv (d, x); |
10549 | 74 endif |
5217 | 75 |
10549 | 76 ## move all the gain into the numerator |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
77 q = q/d(1); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
78 d = d/d(1); |
5217 | 79 endif |
5216 | 80 else |
5217 | 81 lp = numel (p); |
82 if (lp == 1) | |
10549 | 83 q = 0; |
84 return; | |
5217 | 85 elseif (lp == 0) |
10549 | 86 q = []; |
87 return; | |
5216 | 88 endif |
561 | 89 |
5217 | 90 ## Force P to be a row vector. |
91 p = p(:).'; | |
5135 | 92 |
5217 | 93 q = p(1:(lp-1)) .* [(lp-1):-1:1]; |
5216 | 94 endif |
95 else | |
6046 | 96 print_usage (); |
5216 | 97 endif |
561 | 98 |
7411 | 99 endfunction |
5217 | 100 |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
101 |
7411 | 102 %!assert(all (all (polyderiv ([1, 2, 3]) == [2, 2]))); |
103 | |
104 %!assert(polyderiv (13) == 0); | |
105 | |
106 %!error polyderiv ([]); | |
107 | |
108 %!error polyderiv ([1, 2; 3, 4]); | |
109 |