// TITLE     : Formal Integration of a matrix of polynomials
// AUTHOR (C): Samuel GOUGEON - Université du Maine / ENSIM (France)
// RELEASE   : 1.0  (2012-03-23)
// SOFTWARE  : for Scilab > 5.0
// LICENSE  : CeCILL-C
//   http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html
// WARRANTY : None of any kind. Use as is to your own risks & responsability

function iM = integratePoly(M)
    // Integrate each polynomial stored in the matrix M, with respect to 
    //  their (common) variable. 
    // * M may be an hypermatrix of any dimension.
    // * The integration constant is set to zero.
    // * Rational fractions are not supported
    //
    // Example: 
    // M = [ -1+%z 1+2*%z+%z^2 ; 2-%z^3 6]
    // integratePoly(M)
    //
    if argn(2)==0 then
        head_comments("integratePoly")
        M = [ -1+%z 1+2*%z+%z^2 ; 2-%z^3 6]
    end
    s = size(M)
    M = matrix(M,[size(M,"*"),1])
    vn = poly(0,varn(M))
    iM = M*vn
    d = max(degree(iM))
    p = (0:d).*.ones(iM)
    c = coeff(iM)
    k = find(p>0);
    c(k) = c(k)./p(k)
    iM = matrix(inv_coeff(c,d,varn(M)),s)
endfunction
