horner
horner – polynomial evaluation
Calling sequence
R=horner(P,Q, vdim=%f, ttmode=%f)
Parameters
- P: polynomial matrix
- Q: a polynomial or numerical matrix
- vdim, ttmode: optional named boolean arguments.
- R: a cell whose elements are polynomial or numerical matrices if ttmode is false and a
polynomial or a numerical matrix if ttmode is true.
Description
For a polynomial matrix P returns P(Q). The evaluation is performed using the Horner algorithm.
When Q is a numerical matrix the Horner algorithm is a builtin function and when Q is a polynomial
matrix the computation is performed with a library nsp function.
When ttmode is false the returned value is a cell matrix
- if vdim is false the cell matrix has same dimension as P and the cell element (i,j) is
the polynomial matrix P(i,j)(Q).
- if vdim is true the cell matrix has same dimension as Q and the cell element (i,j) is
the polynomial matrix P(Q(i,j)).
When ttmode is true then the operation is a term to term horner which implies that both
matrices have same dimensions (with the usual convention that 1x1 matrices are promoted to any
dimensions). The returned result is then a polynomial matrix.
Examples
- ttmode=%f
p=m2p(1:3); q=m2p(1:2); r=testmatrix('magic',3);
R=horner([p,q],r); // a 1x2 cell R1=horner([p,q],r,vdim=%t); // a 3x3 cell
A=ce2m(R1,indice=1); // a 3x3 matrix B=ce2m(R1,indice=2); // a 3x3 matrix
R.equal[{A,B}] // recovering R from R1.
- ttmode=%t
p=m2p(1:3); q=m2p(1:2); r=[1,2;3,7]; R=horner([p,q;q,p],r,ttmode=%t);