octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: polyvalm.m


From: Ross A. Lippert
Subject: Re: polyvalm.m
Date: Thu, 02 Dec 1999 11:36:15 -0700

Forgot a semi-colon.


## usage: polyvalm (c, x)
##
## Evaluate a polynomial in the matrix sense.
##
## In octave, a polynomial is represented by it's coefficients (arranged
## in descending order). For example a vector c of length n+1
corresponds
## to the following nth order polynomial
##
##   p(x) = c(1) x^n + ... + c(n) x + c(n+1).
##
## polyvalm(c,X) will evaluate the polynomial in the matrix sense, i.e.
matrix
## multiplication is used instead of element by element multiplication
as is
## used in polyval.
##
## X must be a square matrix.
##
## SEE ALSO: polyval, poly, roots, conv, deconv, residue, filter,
##           polyderiv, polyinteg

## Author: Tony Richardson <address@hidden>
## Created: June 1994
## Adapted-By: jwe
## Changed-By: Ross Lippert <address@hidden,sandia.gov>

function y = polyvalm (c, x)

  if (nargin != 2)
    usage ("polyvalm (c, x)");
  endif

  if (! (is_vector (c) || isempty (c)))
    error ("polyvalm: first argument must be a vector.");
  endif

  if (! is_square (x))
    error("polyvalm: second argument must be a square matrix.");
  endif

  if (isempty (c))
    y = [];
    return;
  endif

  n = length(c);
  I = eye(rows(x),columns(x));
  y = c(1) * I;
  for index = 2:n,
     y = c(index)*I + x*y;
  endfor

  if (is_symmetric (x))
    y = (y+y')/2;
  endif

endfunction



reply via email to

[Prev in Thread] Current Thread [Next in Thread]