Mercurial > hg > octave-lyh
annotate scripts/polynomial/polyderiv.m @ 12594:a3a7da1489b2 stable
Modify func.txi discussion of output arguments to include discussion of isargout.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 11 Apr 2011 19:03:32 -0700 |
parents | c792872f8942 |
children |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1994-2011 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 |
5217 | 39 if (nargin == 1 || nargin == 2) |
40 if (! isvector (p)) | |
5216 | 41 error ("polyderiv: argument must be a vector"); |
42 endif | |
5217 | 43 if (nargin == 2) |
44 if (! isvector (a)) | |
10549 | 45 error ("polyderiv: argument must be a vector"); |
5217 | 46 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
47 if (nargout == 1) |
10549 | 48 ## derivative of p*a returns a single polynomial |
49 q = polyderiv (conv (p, a)); | |
5217 | 50 else |
10549 | 51 ## 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
|
52 d = conv (a, a); |
10549 | 53 if (numel (p) == 1) |
54 q = -p * polyderiv (a); | |
55 elseif (numel (a) == 1) | |
56 q = a * polyderiv (p); | |
57 else | |
58 q = conv (polyderiv (p), a) - conv (p, polyderiv (a)); | |
59 q = polyreduce (q); | |
60 endif | |
5217 | 61 |
10549 | 62 ## 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
|
63 x = polygcd (q, d); |
10549 | 64 if (length(x) != 1) |
65 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
|
66 d = deconv (d, x); |
10549 | 67 endif |
5217 | 68 |
10549 | 69 ## 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
|
70 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
|
71 d = d/d(1); |
5217 | 72 endif |
5216 | 73 else |
5217 | 74 lp = numel (p); |
75 if (lp == 1) | |
10549 | 76 q = 0; |
77 return; | |
5217 | 78 elseif (lp == 0) |
10549 | 79 q = []; |
80 return; | |
5216 | 81 endif |
561 | 82 |
5217 | 83 ## Force P to be a row vector. |
84 p = p(:).'; | |
5135 | 85 |
5217 | 86 q = p(1:(lp-1)) .* [(lp-1):-1:1]; |
5216 | 87 endif |
88 else | |
6046 | 89 print_usage (); |
5216 | 90 endif |
561 | 91 |
7411 | 92 endfunction |
5217 | 93 |
7411 | 94 %!assert(all (all (polyderiv ([1, 2, 3]) == [2, 2]))); |
95 | |
96 %!assert(polyderiv (13) == 0); | |
97 | |
98 %!error polyderiv ([]); | |
99 | |
100 %!error polyderiv ([1, 2; 3, 4]); | |
101 |