annotate scripts/polynomial/polyvalm.m @ 30330:01de0045b2e3

maint: Shorten some long lines to <= 80 characters (bug #57599) * audiorecorder.m, disable_diagonal_matrix.m, disable_permutation_matrix.m, disable_range.m, atan2d.m, accumdim.m, bitcmp.m, blkdiag.m, cplxpair.m, dblquad.m, integral2.m, integral3.m, interp2.m, interpn.m, logspace.m, delaunayn.m, griddata3.m, imread.m, genvarname.m, strread.m, nthargout.m, parseparams.m, lsqnonneg.m, qp.m, sqp.m, material.m, __gnuplot_legend__.m, plot.m, __gnuplot_drawnow__.m, polygcd.m, polyvalm.m, setdiff.m, fftfilt.m, eigs.m, betainc.m, cosint.m, factor.m, gallery.m, toeplitz.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, iqr.m, kurtosis.m, quantile.m, bin2dec.m, isstrprop.m, mat2str.m, strchr.m, strsplit.m, __have_feature__.m, datenum.m, datevec.m, eomday.m, weboptions.m: maint: Shorten some long lines to <= 80 characters.
author Rik <rik@octave.org>
date Tue, 23 Nov 2021 13:28:34 -0800
parents 0a5b15007766
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27985
diff changeset
3 ## Copyright (C) 1994-2021 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
8 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
2313
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 ## 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
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
19 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
20 ## 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
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 561
diff changeset
25
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3202
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
27 ## @deftypefn {} {} polyvalm (@var{c}, @var{x})
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
28 ## Evaluate a polynomial in the matrix sense.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3368
diff changeset
29 ##
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3202
diff changeset
30 ## @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
31 ## matrix sense, i.e., matrix multiplication is used instead of element by
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13963
diff changeset
32 ## element multiplication as used in @code{polyval}.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3368
diff changeset
33 ##
3368
a4cd1e9d9962 [project @ 1999-11-20 17:22:48 by jwe]
jwe
parents: 3202
diff changeset
34 ## The argument @var{x} must be a square matrix.
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13963
diff changeset
35 ## @seealso{polyval, roots, poly}
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
36 ## @end deftypefn
1025
f558749713f1 [project @ 1995-01-11 20:52:10 by jwe]
jwe
parents: 904
diff changeset
37
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
38 function y = polyvalm (c, x)
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
39
3085
e6d14959bea9 [project @ 1997-09-19 22:06:12 by jwe]
jwe
parents: 2847
diff changeset
40 if (nargin != 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
41 print_usage ();
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
42 endif
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
43
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3649
diff changeset
44 if (! (isvector (c) || isempty (c)))
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3457
diff changeset
45 error ("polyvalm: first argument must be a vector");
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
46 endif
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
47
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3649
diff changeset
48 if (! issquare (x))
3458
d25bc039237b [project @ 2000-01-19 09:36:14 by jwe]
jwe
parents: 3457
diff changeset
49 error ("polyvalm: second argument must be a square matrix");
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
50 endif
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
51
8903
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
52 n = length (c);
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
53 if (n == 0)
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
54 y = zeros (rows (x), class (x));
3085
e6d14959bea9 [project @ 1997-09-19 22:06:12 by jwe]
jwe
parents: 2847
diff changeset
55 else
8903
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
56 id = eye (rows (x), class (x));
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
57 y = c(1) * id;
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
58 for i = 2:n
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
59 y = y * x + c(i) * id;
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
60 endfor
3085
e6d14959bea9 [project @ 1997-09-19 22:06:12 by jwe]
jwe
parents: 2847
diff changeset
61 endif
561
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
62
e79ff1f4df3c [project @ 1994-07-25 22:32:08 by jwe]
jwe
parents:
diff changeset
63 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
64
8903
c174a1fc3fde reimplement polyvalm using Horner
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
65
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 20852
diff changeset
66 %!assert (! any (polyvalm ([], [1, 2; 3, 4]))(:))
30330
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29358
diff changeset
67 %!assert (polyvalm ([1, 2, 3, 4], [3, -4, 1; -2, 0, 2; -1, 4, -3]),
01de0045b2e3 maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29358
diff changeset
68 %! [117, -124, 11; -70, 36, 38; -43, 92, -45])
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
69
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
70 %!error <must be a square matrix> polyvalm ([1, 1, 1], [1, 2; 3, 4; 5, 6])