Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyvalm.m @ 13258:be74491c20e8
Correct typo in input validation of polynomial functions (Bug #33252)
* ppder.m, ppint.m, ppjumps.m, ppval.m: Correct typo placing negation (!)
only on first isstruct argument rather than combined (isstruct && strcmp)
condition.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 30 Sep 2011 09:20:08 -0700 |
parents | fd0a3ac60b0e |
children | 663594b481e5 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1994-2011 John W. Eaton |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
2 ## Copyright (C) 2009 Jaroslav Hajek |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
904 | 19 |
3368 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} polyvalm (@var{c}, @var{x}) | |
2311 | 22 ## Evaluate a polynomial in the matrix sense. |
3426 | 23 ## |
3368 | 24 ## @code{polyvalm (@var{c}, @var{x})} will evaluate the polynomial in the |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## matrix sense, i.e., matrix multiplication is used instead of element by |
3368 | 26 ## element multiplication as is used in polyval. |
3426 | 27 ## |
3368 | 28 ## The argument @var{x} must be a square matrix. |
3457 | 29 ## @seealso{polyval, poly, roots, conv, deconv, residue, filter, |
10224
f6e0404421f4
point to polyint in @seealso, not polyinteg
John W. Eaton <jwe@octave.org>
parents:
9051
diff
changeset
|
30 ## polyderiv, polyint} |
5642 | 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 |
2312 | 37 function y = polyvalm (c, x) |
561 | 38 |
3085 | 39 if (nargin != 2) |
6046 | 40 print_usage (); |
561 | 41 endif |
42 | |
4030 | 43 if (! (isvector (c) || isempty (c))) |
3458 | 44 error ("polyvalm: first argument must be a vector"); |
561 | 45 endif |
46 | |
4030 | 47 if (! issquare (x)) |
3458 | 48 error ("polyvalm: second argument must be a square matrix"); |
561 | 49 endif |
50 | |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
51 n = length (c); |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
52 if (n == 0) |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
53 y = zeros (rows (x), class (x)); |
3085 | 54 else |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
55 id = eye (rows (x), class (x)); |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
56 y = c(1) * id; |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
57 for i = 2:n |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
58 y = y * x + c(i) * id; |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
59 endfor |
3085 | 60 endif |
561 | 61 |
62 endfunction | |
7411 | 63 |
8903
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
64 |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
65 %!assert(! any (polyvalm ([], [1, 2; 3, 4]))(:)); |
c174a1fc3fde
reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
66 %!assert(polyvalm ([1, 2, 3, 4], [3, -4, 1; -2, 0, 2; -1, 4, -3]), [117, -124, 11; -70, 36, 38; -43, 92, -45]) |
7411 | 67 |
68 %!error polyvalm ([1, 1, 1], [1, 2; 3, 4; 5, 6]); | |
69 |