Previous Next Contents

8  Polynomial calculations

8.1   bezout Bezout equation for polynomials




CALLING SEQUENCE :

[thegcd,U]=bezout(p1,p2) 



PARAMETERS :




DESCRIPTION :

[thegcd,U]=bezout(p1,p2) computes GCD thegcd of p1 and p2 and in addition a (2x2) unimodular matrix U such that:

[p1,p2]*U = [thegcd,0]


The lcm of p1 and p2 is given by:

p1*U(1,2)
(or -p2*U(2,2))


EXAMPLE :

x=poly(0,'x');
p1=(x+1)*(x-3)^5;p2=(x-2)*(x-3)^3;
[thegcd,U]=bezout(p1,p2) 
det(U)
clean([p1,p2]*U)
thelcm=p1*U(1,2)
lcm([p1,p2])



See Also : poly X, roots X, simp X, clean X, lcm X



8.2   clean cleans matrices (round to zero small entries)




CALLING SEQUENCE :

[B]=clean(A [,epsa [,epsr]])



PARAMETERS :




DESCRIPTION :

This function eliminates (i.e. set to zero) all the coefficients with absolute value < epsa and relative value < epsr (relative means relative w.r.t. 1-norm of coefficients) in a polynomial (possibly matrix polynomial or rational matrix).

Default values are epsa=1.d-10
and epsr=1.d-10;

For a constant (non polynomial) matrix clean(A,epsa) sets to zero all entries of A smaller than epsa.


EXAMPLE :

x=poly(0,'x');
w=[x,1,2+x;3+x,2-x,x^2;1,2,3+x]/3;
w*inv(w)
clean(w*inv(w))

8.3   cmndred common denominator form




CALLING SEQUENCE :

[n,d]=cmndred(num,den)



PARAMETERS :




DESCRIPTION :

[n,d]=cmndred(num,den) computes a polynomial matrix n and a common denominator polynomial d such that:

n/d=num./den


The rational matrix defined by num./den is n/d


See Also : simp X, clean X



8.4   coffg inverse of polynomial matrix




CALLING SEQUENCE :

[Ns,d]=coffg(Fs) 



PARAMETERS :




DESCRIPTION :

coffg computes Fs^-1 where Fs is a polynomial matrix by co-factors method.

Fs
inverse = Ns/d

d = common denominator; Ns = numerator (a polynomial matrix)

(For large matrices,be patient...results are generally reliable)


EXAMPLE :

s=poly(0,'s')
a=[ s, s^2+1; s  s^2-1];
[a1,d]=coffg(a);
(a1/d)-inv(a)



See Also : determ X, detr X, invr X, penlaur X, glever X


Author : F. D.



8.5   colcompr column compression of polynomial matrix




CALLING SEQUENCE :

[Y,rk,ac]=colcompr(A);



PARAMETERS :




DESCRIPTION :

column compression of polynomial matrix A (compression to the left)


EXAMPLE :

s=poly(0,'s');
p=[s;s*(s+1)^2;2*s^2+s^3];
[Y,rk,ac]=colcompr(p*p');
p*p'*Y



See Also : rowcompr X



8.6   denom denominator




CALLING SEQUENCE :

den=denom(r)



PARAMETERS :




DESCRIPTION :

den=denom(r) returns the denominator of a rational matrix.

Since rationals are internally represented as r=list(['r','num','den','dt'],num,den,[])
, denom(r) is the same as r(3) or r('den') .


See Also : numer X



8.7   derivat rational matrix derivative




CALLING SEQUENCE :

pd=derivat(p)  



PARAMETERS :




DESCRIPTION :

computes the derivative of the polynomial or rational function matrix w.r.t the dummy variable.


EXAMPLE :

s=poly(0,'s');
derivat(1/s)  // -1/s^2;

8.8   determ determinant of polynomial matrix




CALLING SEQUENCE :

res=determ(W [,k])



PARAMETERS :




DESCRIPTION :

res=determ(W [,k]) returns the determinant of a real polynomial matrix (computation made by FFT).

k
is an integer larger than the actual degree of the determinant of W.

The default value of k
is the smallest power of 2 which is larger than n*maxi(degree(W)).

Method: evaluate the determinant of W
for the Fourier frequencies and apply inverse FFT to the coefficients of the determinant.


EXAMPLE :

s=poly(0,'s');
w=s*rand(10,10);
determ(w)
det(coeff(w,1))*s^10



See Also : det X, detr X, coffg X


Author : F.D.



8.9   detr polynomial determinant




CALLING SEQUENCE :

d=detr(h)



PARAMETERS :




DESCRIPTION :

d=detr(h) returns the determinant d of the polynomial or rational function matrix h. Based on Leverrier's algorithm.


See Also : det X, determ X



8.10   diophant diophantine (Bezout) equation




CALLING SEQUENCE :

[x,err]=diophant(p1p2,b)



PARAMETERS :




DESCRIPTION :

diophant solves the bezout equation:

p1*x1+p2*x2=b
with p1p2 a polynomial vector. If the equation is not solvable
err=||p1*x1+p2*x2-b||/||b||
else err=0


EXAMPLE  :

s=poly(0,'s');p1=(s+3)^2;p2=(1+s);
x1=s;x2=(2+s);
[x,err]=diophant([p1,p2],p1*x1+p2*x2);
p1*x1+p2*x2-p1*x(1)-p2*x(2)

8.11   factors numeric real factorization




CALLING SEQUENCE :

[lnum,g]=factors(pol [,'flag'])
[lnum,lden,g]=factors(rat [,'flag'])
rat=factors(rat,'flag')



PARAMETERS :




DESCRIPTION :

returns the factors of polynomial pol in the list lnum and the "gain" g.

One has pol= g times product of entries of the list lnum
(if flag is not given). If flag='c' is given, then one has |pol(i omega)| = |g*prod(lnum_j(i omega)|. If flag='d' is given, then one has |pol(exp(i omega))| = |g*prod(lnum_i(exp(i omega))|. If argument of factors is a 1x1 rational rat=pol1/pol2, the factors of the numerator pol1 and the denominator pol2 are returned in the lists lnum and lden respectively.

The "gain" is returned as g
,i.e. one has: rat= g times (product entries in lnum) / (product entries in lden).

If flag
is 'c' (resp. 'd'), the roots of pol are refected wrt the imaginary axis (resp. the unit circle), i.e. the factors in lnum are stable polynomials.

Same thing if factors
is invoked with a rational arguments: the entries in lnum and lden are stable polynomials if flag is given. R2=factors(R1,'c') or R2=factors(R1,'d') with R1 a rational function or SISO syslin list then the output R2 is a transfer with stable numerator and denominator and with same magnitude as R1 along the imaginary axis ('c') or unit circle ('d').


EXAMPLE :

n=poly([0.2,2,5],'z');
d=poly([0.1,0.3,7],'z');
R=syslin('d',n,d);
R1=factors(R,'d')
roots(R1('num'))
roots(R1('den'))
w=exp(2*%i*%pi*[0:0.1:1]);
norm(abs(horner(R1,w))-abs(horner(R,w)))



See Also : simp X



8.12   gcd gcd calculation




CALLING SEQUENCE :

[pgcd,U]=gcd(p)



PARAMETERS :




DESCRIPTION :

[pgcd,u]=gcd(p) computes the gcd of components of p and a unimodular matrix (with polynomial inverse) U, with minimal degree such that

p*U=[0 ... 0 pgcd]



EXAMPLE  :

s=poly(0,'s');
p=[s,s*(s+1)^2,2*s^2+s^3];
[pgcd,u]=gcd(p);
p*u



See Also : bezout X, lcm X, hermit X



8.13   hermit Hermite form




CALLING SEQUENCE :

[Ar,U]=hermit(A)



PARAMETERS :




DESCRIPTION :

Hermite form: U is an unimodular matrix such that A*U is in Hermite triangular form:

The output variable is Ar=A*U
.

Warning: Experimental version


EXAMPLE  :

s=poly(0,'s');
p=[s, s*(s+1)^2, 2*s^2+s^3];
[Ar,U]=hermit(p'*p);
clean(p'*p*U), det(U)



See Also : hrmt X, htrianr X



8.14   horner polynomial/rational evaluation




CALLING SEQUENCE :

horner(P,x) 



PARAMETERS :




DESCRIPTION :

evaluates the polynomial or rational matrix P = P(s) when the variable s of the polynomial is replaced by x:

horner(P,x)
=P(x)

Example (Bilinear transform): Assume P = P(s) is a rational matrix then the rational matrix P((1+s)/(1-s)) is obtained by horner(P,(1+s)/(1-s)).

To evaluate a rational matrix at given frequencies use preferably the freq
primitive.


EXAMPLES :

s=poly(0,'s');M=[s,1/s];
horner(M,1)
horner(M,%i)
horner(M,1/s)



See Also : freq X, repfreq X, evstr X



8.15   hrmt gcd of polynomials




CALLING SEQUENCE :

[pg,U]=hrmt(v)



PARAMETERS :




DESCRIPTION :

[pg,U]=hrmt(v) returns a unimodular matrix U and pg = gcd of row of polynomials v such that v*U = [pg,0].


EXAMPLE :

x=poly(0,'x');
v=[x*(x+1),x^2*(x+1),(x-2)*(x+1),(3*x^2+2)*(x+1)];
[pg,U]=hrmt(v);U=clean(U)
det(U)



See Also : gcd X, htrianr X



8.16   htrianr triangularization of polynomial matrix




CALLING SEQUENCE :

[Ar,U,rk]=htrianr(A)



PARAMETERS :




DESCRIPTION :

triangularization of polynomial matrix A.

A
is [m,n] , m <= n.

Ar=A*U


Warning: there is an elimination of "small" terms (see function code).


EXAMPLE :

x=poly(0,'x');
M=[x;x^2;2+x^3]*[1,x-2,x^4];
[Mu,U,rk]=htrianr(M)
det(U)
M*U(:,1:2)



See Also : hrmt X, colcompr X



8.17   invr inversion of (rational) matrix




CALLING SEQUENCE :

F = invr(H)



PARAMETERS :




DESCRIPTION :

If H is a polynomial or rational function matrix, invr computes H^(-1) using Leverrier's algorithm (see function code)


EXAMPLE :

s=poly(0,'s')
H=[s,s*s+2;1-s,1+s]; invr(H)
[Num,den]=coffg(H);Num/den
H=[1/s,(s+1);1/(s+2),(s+3)/s];invr(H)



See Also : glever X, coffg X, inv X



8.18   lcm least common multiple




CALLING SEQUENCE :

[pp,fact]=lcm(p)



PARAMETERS :




DESCRIPTION :

pp=lcm(p) computes the lcm pp of polynomial vector p.

[pp,fact]=lcm(p)
computes in addition the vector fact such that:

p.*fact=pp*ones(p)



EXAMPLE  :

s=poly(0,'s');
p=[s,s*(s+1)^2,s^2*(s+2)];
[pp,fact]=lcm(p);
p.*fact, pp



See Also : gcd X, bezout X



8.19   lcmdiag least common multiple diagonal factorization




CALLING SEQUENCE :

[N,D]=lcmdiag(H)
[N,D]=lcmdiag(H,flag)



PARAMETERS :




DESCRIPTION :

[N,D]=lcmdiag(H,'row') computes a factorization D*H=N, i.e. H=D^(-1)*N where D is a diagonal matrix with D(k,k)=lcm of kth row of H('den').

[N,D]=lcmdiag(H)
or [N,D]=lcmdiag(H,'col) returns H=N*D^(-1) with diagonal D and D(k,k)=lcm of kth col of H('den')


EXAMPLE  :

s=poly(0,'s');
H=[1/s,(s+2)/s/(s+1)^2;1/(s^2*(s+2)),2/(s+2)];
[N,D]=lcmdiag(H);
N/D-H



See Also : lcm X, gcd X, bezout X



8.20   ldiv polynomial matrix long division




CALLING SEQUENCE :

[x]=ldiv(n,d,k) 



PARAMETERS :




DESCRIPTION :

x=ldiv(n,d,k) gives the k first coefficients of the long division of n by d i.e. the Taylor expansion of the rational matrix [nij(z)/dij(z)] near infinity.

Coefficients of expansion of nij/dij
are stored in x((i-1)*n+k,j) k=1:n


EXAMPLE :

wss=ssrand(1,1,3);[a,b,c,d]=abcd(wss);
wtf=ss2tf(wss);
x1=ldiv(numer(wtf),denom(wtf),5)
x2=[c*b;c*a*b;c*a^2*b;c*a^3*b;c*a^4*b]
wssbis=markp2ss(x1',5,1,1);
wtfbis=clean(ss2tf(wssbis))
x3=ldiv(numer(wtfbis),denom(wtfbis),5)



See Also : arl2 X, markp2ss X, pdiv X



8.21   numer numerator




CALLING SEQUENCE :

NUM=numer(R)



PARAMETERS :




DESCRIPTION :

Utility fonction. NUM=numer(R) returns the numerator NUM of a rational function matrix R (R may be also a constant or polynomial matrix). numer(R) is equivalent to R(2) or R('num')


See Also : denom X



8.22   pdiv polynomial division




CALLING SEQUENCE :

[R,Q]=pdiv(P1,P2)
[Q]=pdiv(P1,P2)



PARAMETERS :




DESCRIPTION :

Element-wise euclidan division of the polynomial matrix P1 by the polynomial P2 or by the polynomial matrix P2. Rij is the matrix of remainders, Qij is the matrix of quotients and P1ij = Qij*P2 + Qij or P1ij = Qij*P2ij + Qij.


EXAMPLE :

x=poly(0,'x');
p1=(1+x^2)*(1-x);p2=1-x;
[r,q]=pdiv(p1,p2)
p2*q-p1
p2=1+x;
[r,q]=pdiv(p1,p2)
p2*q+r-p1



See Also : ldiv X, gcd X



8.23   pol2des polynomial matrix to descriptor form




CALLING SEQUENCE :

[N,B,C]=pol2des(Ds)



PARAMETERS :




DESCRIPTION :

Given the polynomial matrix Ds=D_0 +D_1 s +D_2 s^2 +... +D_k s^k, pol2des returns three matrices N, B, C, with N nilpotent such that:

Ds = C (s*N-eye())^-1 B



EXAMPLE :

s=poly(0,'s');
G=[1,s;1+s^2,3*s^3];[N,B,C]=pol2des(G);
G1=clean(C*inv(s*N-eye())*B),G2=numer(G1)



See Also : ss2des X, tf2des X


Author : F.D.



8.24   pol2str polynomial to string conversion




CALLING SEQUENCE :

[str]=pol2str(p) 



PARAMETERS :




DESCRIPTION :

converts polynomial to character string (utility function).


See Also : string X, pol2tex X



8.25   polfact minimal factors




CALLING SEQUENCE :

[f]=polfact(p)



PARAMETERS :




DESCRIPTION :

f=polfact(p) returns the minimal factors of p i.e. f=[f0 f1 ... fn] such that p=prod(f)


See Also : lcm X, cmndred X, factors X



8.26   residu residue




CALLING SEQUENCE :

[V]=residu(P,Q1,Q2)



PARAMETERS :




DESCRIPTION :

V=residu(P,Q1,Q2) returns the matrix V such that V(i,j) is the sum of the residues of the rational fraction P(i,j)/(Q1(i,j)*Q2(i,j)) calculated at the zeros of Q1(i,j).

Q1(i,j)
and Q2(i,j) must not have any common root.


EXAMPLE :

s=poly(0,'s');
H=[s/(s+1)^2,1/(s+2)];N=numer(H);D=denom(H);
w=residu(N.*horner(N,-s),D,horner(D,-s));  //N(s) N(-s) / D(s) D(-s)
sqrt(sum(w))  //This is H2 norm
h2norm(tf2ss(H))
//
p=(s-1)*(s+1)*(s+2)*(s+10);a=(s-5)*(s-1)*(s*s)*((s+1/2)**2);
b=(s-3)*(s+2/5)*(s+3);
residu(p,a,b)+531863/4410    //Exact
z=poly(0,'z');a=z^3+0.7*z^2+0.5*z-0.3;b=z^3+0.3*z^2+0.2*z+0.1;
atild=gtild(a,'d');btild=gtild(b,'d');
residu(b*btild,z*a,atild)-2.9488038   //Exact
a=a+0*%i;b=b+0*%i;
real(residu(b*btild,z*a,atild)-2.9488038) //Complex case



See Also : pfss X, bdiag X, roots X, poly X, gtild X


Author : F.D.



8.27   roots roots of polynomials




CALLING SEQUENCE :

[x]=roots(p)



PARAMETERS :




DESCRIPTION :

x=roots(p) returns in the complex vector x the roots of the polynomial p. Degree of p must be <=100.


EXAMPLE :

p=poly([0,10,1+%i,1-%i],'x');
roots(p)
A=rand(3,3);roots(poly(A,'x'))    // Evals by characteristic polynomial
spec(A) 



See Also : poly X



8.28   routh_t Routh's table




CALLING SEQUENCE :

r=routh_t(h [,k]).



PARAMETERS :




DESCRIPTION :

r=routh_t(h,k) computes Routh's table of denominator of the system described by transfer matrix SISO h with the feedback by the gain k.

If k=poly(0,'k')
we will have a polynomial matrix with dummy variable k, formal expression of the Routh table.



8.29   rowcompr row compression of polynomial matrix




CALLING SEQUENCE :

[X,rk,Ac]=rowcompr(A)



PARAMETERS :




DESCRIPTION :

row compression of polynomial matrix A .

X
is a left polynomial unimodular basis which row compressed thee rows of A. rk is the normal rank of A.

Warning: elimination of "small" terms (use with care!).


See Also : colcompr X



8.30   sfact discrete time spectral factorization




CALLING SEQUENCE :

F=sfact(P)



PARAMETERS :




DESCRIPTION :

Finds F, a spectral factor of P. P is a polynomial matrix such that each root of P has a mirror image w.r.t the unit circle. Problem is singular if a root is on the unit circle.

sfact(P) returns a polynomial matrix F(z) which is antistable and such that

P = F(z)* F(1/z) *z^n


For scalar polynomials a specific algorithm is implemented. Algorithms are adapted from Kucera's book.


EXAMPLE :

//Simple polynomial example
z=poly(0,'z');
p=(z-1/2)*(2-z)
w=sfact(p);
w*numer(horner(w,1/z))
//matrix example
F1=[z-1/2,z+1/2,z^2+2;1,z,-z;z^3+2*z,z,1/2-z];
P=F1*gtild(F1,'d');  //P is symmetric
F=sfact(P)    
roots(det(P))  
roots(det(gtild(F,'d')))  //The stable roots
roots(det(F))             //The antistable roots
clean(P-F*gtild(F,'d'))
//Example of continuous time use
s=poly(0,'s');
p=-3*(s+(1+%i))*(s+(1-%i))*(s+0.5)*(s-0.5)*(s-(1+%i))*(s-(1-%i));p=real(p);
//p(s) = polynomial in s^2 , looks for stable f such that p=f(s)*f(-s) 
w=horner(p,(1-s)/(1+s));  // bilinear transform w=p((1-s)/(1+s))
wn=numer(w);              //take the numerator
fn=sfact(wn);f=numer(horner(fn,(1-s)/(s+1))); //Factor and back transform
f=f/sqrt(horner(f*gtild(f,'c'),0));f=f*sqrt(horner(p,0));      //normalization
roots(f)    //f is stable
clean(f*gtild(f,'c')-p)    //f(s)*f(-s) is p(s) 



See Also : gtild X, fspecg X



8.31   simp rational simplification




CALLING SEQUENCE :

[N1,D1]=simp(N,D)
H1=simp(H)



PARAMETERS :




DESCRIPTION :

[n1,d1]=simp(n,d) calculates two polynomials n1 and d1 such that n1/d1 = n/d.

If N
and D are polynomial matrices the calculation is performed element-wise.

H1=simp(H)
is also valid (each entry of H is simplified in H1).

Caution:

-no threshold is given i.e. simp
cannot forces a simplification.

-For linear dynamic systems which include integrator(s) simplification changes the static gain. (H(0)
for continuous systems or H(1) for discrete systems)

-for complex data, simp
returns its input(s).

-rational simplification is called after nearly each operations on rationals. It is possible to toggle simplification on or off using simp_mode
function.


EXAMPLES :

s=poly(0,'s');
[n,d]=simp((s+1)*(s+2),(s+1)*(s-2))

simp_mode(%F);hns=s/s
simp_mode(%T);hns=s/s




See Also : roots X, trfmod X, poly X, clean X, simp_mode X



8.32   simp_mode toggle rational simplification




CALLING SEQUENCE :

mod=simp_mode()
simp_mode(mod)



PARAMETERS :




DESCRIPTION :

rational simplification is called after nearly each operations on rationals. It is possible to toggle simplification on or off using simp_mode function.

simp_mod(%t)
set rational simplification mode on

simp_mod(%f)
set rational simplification mode off

mod=simp_mod()
returns in mod the current rational simplification mode


EXAMPLES :

s=poly(0,'s');
mod=simp_mode()
simp_mode(%f);hns=s/s
simp_mode(%t);hns=s/s
simp_mode(mod);




See Also : simp X



8.33   sylm Sylvester matrix




CALLING SEQUENCE :

[S]=sylm(a,b)



PARAMETERS :




DESCRIPTION :

sylm(a,b) gives the Sylvester matrix associated to polynomials a and b, i.e. the matrix S such that:

coeff( a*x + b*y )' = S * [coeff(x)';coeff(y)']
.

Dimension of S
is equal to degree(a)+degree(b).

If a
and b are coprime polynomials then

rank(sylm(a,b))=degree(a)+degree(b))
and the instructions
  u = sylm(a,b) \\ eye(na+nb,1)
  x = poly(u(1:nb),'z','coeff')
  y = poly(u(nb+1:na+nb),'z','coeff')
compute Bezout factors x and y of minimal degree such that a*x+b*y = 1



8.34   systmat system matrix




CALLING SEQUENCE :

[Sm]=systmat(Sl);



PARAMETERS :




DESCRIPTION :

System matrix of the linear system Sl (syslin list) in state-space form (utility function).
 Sm = [-sI + A   B;
      [    C     D]
For a descriptor system (Sl=list('des',A,B,C,D,E)), systmat returns:
 Sm = [-sE + A   B;
      [    C     D]



See Also : ss2des X, sm2des X, sm2ss X


Previous Next Contents