Mercurial > octave
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 |
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 | 7 ## |
8 ## This file is part of Octave. | |
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 | 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 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 | 25 |
3368 | 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 | 28 ## Evaluate a polynomial in the matrix sense. |
3426 | 29 ## |
3368 | 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 | 33 ## |
3368 | 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 | 36 ## @end deftypefn |
1025 | 37 |
2312 | 38 function y = polyvalm (c, x) |
561 | 39 |
3085 | 40 if (nargin != 2) |
6046 | 41 print_usage (); |
561 | 42 endif |
43 | |
4030 | 44 if (! (isvector (c) || isempty (c))) |
3458 | 45 error ("polyvalm: first argument must be a vector"); |
561 | 46 endif |
47 | |
4030 | 48 if (! issquare (x)) |
3458 | 49 error ("polyvalm: second argument must be a square matrix"); |
561 | 50 endif |
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 | 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 | 61 endif |
561 | 62 |
63 endfunction | |
7411 | 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 | 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]) |