Mercurial > octave
view scripts/polynomial/polyvalm.m @ 27981:7f1cec12c240
maint: Remove simple "Adapted-By:" lines from code base.
* __ftp__.cc, urlwrite.cc, lin2mu.m, mu2lin.m, bincoeff.m, common_size.m,
nextpow2.m, shift.m, xor.m, griddata.m, colormap.m, gray.m, gray2ind.m,
image.m, imagesc.m, imshow.m, ind2gray.m, ind2rgb.m, ocean.m, rgb2ind.m,
findstr.m, commutation_matrix.m, cross.m, gls.m, isdefinite.m, ishermitian.m,
issymmetric.m, null.m, ols.m, orth.m, qzhess.m, vech.m, orderfields.m, untar.m,
unzip.m, orient.m, __pltopt__.m, __gnuplot_print__.m, subplot.m, compan.m,
conv.m, deconv.m, poly.m, polyder.m, polyfit.m, polyint.m, polyreduce.m,
polyval.m, polyvalm.m, residue.m, roots.m, detrend.m, fftconv.m, fftfilt.m,
fftshift.m, ifftshift.m, beta.m, lcm.m, pow2.m, corr.m, kurtosis.m, skewness.m,
base2dec.m, bin2dec.m, blanks.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m,
hex2dec.m, index.m, rindex.m, substr.m, calendar.m, datestr.m, datevec.m,
eomday.m, now.m, weekday.m:
Remove simple "Adapted-By:" lines from code base.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 21 Jan 2020 13:15:15 -0800 |
parents | bdad8ca48700 |
children | 9f9ac219896d |
line wrap: on
line source
######################################################################## ## ## Copyright (C) 1994-2020 The Octave Project Developers ## ## See the file COPYRIGHT.md in the top-level directory of this ## distribution or <https://octave.org/copyright/>. ## ## This file is part of Octave. ## ## Octave is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## <https://www.gnu.org/licenses/>. ## ######################################################################## ## -*- texinfo -*- ## @deftypefn {} {} polyvalm (@var{c}, @var{x}) ## Evaluate a polynomial in the matrix sense. ## ## @code{polyvalm (@var{c}, @var{x})} will evaluate the polynomial in the ## matrix sense, i.e., matrix multiplication is used instead of element by ## element multiplication as used in @code{polyval}. ## ## The argument @var{x} must be a square matrix. ## @seealso{polyval, roots, poly} ## @end deftypefn ## Author: Tony Richardson <arichard@stark.cc.oh.us> function y = polyvalm (c, x) if (nargin != 2) print_usage (); endif if (! (isvector (c) || isempty (c))) error ("polyvalm: first argument must be a vector"); endif if (! issquare (x)) error ("polyvalm: second argument must be a square matrix"); endif n = length (c); if (n == 0) y = zeros (rows (x), class (x)); else id = eye (rows (x), class (x)); y = c(1) * id; for i = 2:n y = y * x + c(i) * id; endfor endif endfunction %!assert (! any (polyvalm ([], [1, 2; 3, 4]))(:)) %!assert (polyvalm ([1, 2, 3, 4], [3, -4, 1; -2, 0, 2; -1, 4, -3]), [117, -124, 11; -70, 36, 38; -43, 92, -45]) %!error <must be a square matrix> polyvalm ([1, 1, 1], [1, 2; 3, 4; 5, 6])