annotate scripts/polynomial/polyder.m @ 13176:9b8e786bbf3c

maint: use specific endif, endfor tokens instead of simple end * strread.m, __go_draw_axes__.m, ppval.m: Use specific endif, endfor tokens instead of simple end.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Sep 2011 15:41:35 -0400
parents b7a6a3644f3b
children 614505385171
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12803
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
1 ## Copyright (C) 1994-2011 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1597
cf77ebb2719b [project @ 1995-11-01 00:48:17 by jwe]
jwe
parents:
diff changeset
18
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3446
diff changeset
19 ## -*- texinfo -*-
12803
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
20 ## @deftypefn {Function File} {} polyder (@var{p})
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
21 ## @deftypefnx {Function File} {[@var{k}] =} polyder (@var{a}, @var{b})
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
22 ## @deftypefnx {Function File} {[@var{q}, @var{d}] =} polyder (@var{b}, @var{a})
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
23 ## Return the coefficients of the derivative of the polynomial whose
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
24 ## coefficients are given by the vector @var{p}. If a pair of polynomials
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
25 ## is given, return the derivative of the product @math{@var{a}*@var{b}}.
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
26 ## 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
27 ## 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
28 ## in @var{q} and the denominator in @var{d}.
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
29 ## @seealso{poly, polyint, polyreduce, roots, conv, deconv, residue,
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
30 ## filter, polygcd, polyval, polyvalm}
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3446
diff changeset
31 ## @end deftypefn
1597
cf77ebb2719b [project @ 1995-11-01 00:48:17 by jwe]
jwe
parents:
diff changeset
32
12803
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
33 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
34 ## Created: June 1994
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
35 ## Adapted-By: jwe
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
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] = polyder (p, a)
1597
cf77ebb2719b [project @ 1995-11-01 00:48:17 by jwe]
jwe
parents:
diff changeset
38
12803
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
39 if (nargin == 1 || nargin == 2)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
40 if (! isvector (p))
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
41 error ("polyder: argument must be a vector");
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
42 endif
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
43 if (nargin == 2)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
44 if (! isvector (a))
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
45 error ("polyder: argument must be a vector");
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
46 endif
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
47 if (nargout == 1)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
48 ## derivative of p*a returns a single polynomial
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
49 q = polyder (conv (p, a));
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
50 else
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
51 ## derivative of p/a returns numerator and denominator
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
52 d = conv (a, a);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
53 if (numel (p) == 1)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
54 q = -p * polyder (a);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
55 elseif (numel (a) == 1)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
56 q = a * polyder (p);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
57 else
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
58 q = conv (polyder (p), a) - conv (p, polyder (a));
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
59 q = polyreduce (q);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
60 endif
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
61
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
62 ## remove common factors from numerator and denominator
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
63 x = polygcd (q, d);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
64 if (length(x) != 1)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
65 q = deconv (q, x);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
66 d = deconv (d, x);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
67 endif
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
68
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
69 ## move all the gain into the numerator
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
70 q = q/d(1);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
71 d = d/d(1);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
72 endif
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 3458
diff changeset
73 else
12803
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
74 lp = numel (p);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
75 if (lp == 1)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
76 q = 0;
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
77 return;
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
78 elseif (lp == 0)
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
79 q = [];
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
80 return;
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
81 endif
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
82
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
83 ## Force P to be a row vector.
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
84 p = p(:).';
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
85
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
86 q = p(1:(lp-1)) .* [(lp-1):-1:1];
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 3458
diff changeset
87 endif
1597
cf77ebb2719b [project @ 1995-11-01 00:48:17 by jwe]
jwe
parents:
diff changeset
88 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
89 print_usage ();
1597
cf77ebb2719b [project @ 1995-11-01 00:48:17 by jwe]
jwe
parents:
diff changeset
90 endif
cf77ebb2719b [project @ 1995-11-01 00:48:17 by jwe]
jwe
parents:
diff changeset
91
cf77ebb2719b [project @ 1995-11-01 00:48:17 by jwe]
jwe
parents:
diff changeset
92 endfunction
12803
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
93
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
94
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
95 %!assert(all (all (polyder ([1, 2, 3]) == [2, 2])));
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
96 %!assert(polyder (13) == 0);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
97
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
98 %!error polyder ([]);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
99 %!error polyder ([1, 2; 3, 4]);
b7a6a3644f3b codesprint: Deprecate polyderiv.m
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
100