annotate scripts/deprecated/polyderiv.m @ 15104:093961d9ebed gui

Fixed self-assignment bug found by Torsten. * find-dialog.cc: Fixed self-assignment in constructor.
author Jacob Dawid <jacob.dawid@gmail.com>
date Sat, 04 Aug 2012 10:53:58 +0200
parents 72c96de7a403
children 1c89599167a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
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: 2312
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: 6850
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: 6850
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
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: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
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: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
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: 6850
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: 6850
diff changeset
17 ## <http://www.gnu.org/licenses/>.
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 561
diff changeset
18
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3202
diff changeset
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
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3202
diff changeset
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
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
30 ## filter, polygcd, polyval, polyvalm}
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3202
diff changeset
31 ## @end deftypefn
1025
f558749713f1 [project @ 1995-01-11 20:52:10 by jwe]
jwe
parents: 904
diff changeset
32
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3085
diff changeset
33 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
34 ## Created: June 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
35 ## Adapted-By: jwe
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
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] = polyderiv (p, a)
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
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
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
46 if (nargin == 1 || nargin == 2)
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
47 if (! isvector (p))
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
48 error ("polyderiv: argument must be a vector");
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
49 endif
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
50 if (nargin == 2)
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
51 if (! isvector (a))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
52 error ("polyderiv: argument must be a vector");
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
55 ## derivative of p*a returns a single polynomial
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
56 q = polyderiv (conv (p, a));
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
57 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
60 if (numel (p) == 1)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
61 q = -p * polyderiv (a);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
62 elseif (numel (a) == 1)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
63 q = a * polyderiv (p);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
64 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
65 q = conv (polyderiv (p), a) - conv (p, polyderiv (a));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
66 q = polyreduce (q);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
67 endif
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
68
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
71 if (length(x) != 1)
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
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
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
74 endif
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
75
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
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
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
79 endif
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
80 else
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
81 lp = numel (p);
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
82 if (lp == 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
83 q = 0;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
84 return;
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
85 elseif (lp == 0)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
86 q = [];
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
87 return;
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
88 endif
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
89
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
90 ## Force P to be a row vector.
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
91 p = p(:).';
5135
8eaef366ab43 [project @ 2005-02-09 07:59:37 by jwe]
jwe
parents: 5053
diff changeset
92
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
93 q = p(1:(lp-1)) .* [(lp-1):-1:1];
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
94 endif
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
95 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
96 print_usage ();
5216
5ed60b8b1ac4 [project @ 2005-03-16 19:51:39 by jwe]
jwe
parents: 5135
diff changeset
97 endif
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
98
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
99 endfunction
5217
e88886a6934d [project @ 2005-03-16 20:03:01 by jwe]
jwe
parents: 5216
diff changeset
100
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
101 %!assert(all (all (polyderiv ([1, 2, 3]) == [2, 2])));
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
102
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
103 %!assert(polyderiv (13) == 0);
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
104
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
105 %!error polyderiv ([]);
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
106
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
107 %!error polyderiv ([1, 2; 3, 4]);
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
108