2.4 Polynomials and Polynomial Matrices

Polynomials are easily created and manipulated in Scilab. Manipulation of polynomial matrices is essentially identical to that of constant matrices. The poly primitive in Scilab can be used to specify the coefficients of a polynomial or the roots of a polynomial.

-->p=poly([1 2],'s')   //polynomial defined by its roots
 p         =
 
              2  
    2 - 3s + s   
 
-->q=poly([1 2],'s','c')  //polynomial defined by its coefficients
 q         =
 
    1 + 2s   
 
-->p+q
 ans       =
 
             2  
    3 - s + s   
 
-->p*q
 ans       =
 
              2    3  
    2 + s - 5s + 2s   
 
--> q/p
 ans       =
 
      1 + 2s     
    -----------  
              2  
    2 - 3s + s
Note that the polynomial p has the roots 1 and 2 whereas the polynomial q has the coefficients 1 and 2. It is the third argument in the poly primitive which specifies the coefficient flag option. In the case where the first argument of poly is a square matrix and the roots option is in effect the result is the characteristic polynomial of the matrix.
 
--> poly([1 2;3 4],'s')
 ans       =
 
              2  
  - 2 - 5s + s
Polynomials can be added, subtracted, multiplied, and divided, as usual, but only between polynomials of same formal variable.

Polynomials, like real and complex constants, can be used as elements in matrices. This is a very useful feature of Scilab for systems theory.

 
-->s=poly(0,'s');
 
-->A=[1 s;s 1+s^2]
 A         =
 
!   1     s      !
!                !
!              2 !
!   s     1 + s  !
 
--> B=[1/s 1/(1+s);1/(1+s) 1/s^2]
 B         =
 
!   1           1    !
! ------      ------ !
!   s         1 + s  !
!                    !
!     1       1      !
!    ---     ---     !
!              2     !
!   1 + s     s      !
From the above examples it can be seen that matrices can be constructed from polynomials and rationals.



Sous-sections