1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises
5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0,
7// pursuant to article 5.3.4 of the CeCILL v.2.1.
8// This file was originally licensed under the terms of the CeCILL v2.1,
9// and continues to be available under such terms.
10// For more information, see the COPYING file which you should have received
11// along with this program.
12
13function f = %p_j_s(p,s)
14    // %p_j_s(p,s)  computes p.^s for p polynomial matrix in special cases
15    //!
16
17    if s==[] then f=[],return,end
18    if  or(imag(s)<>0)|or(int(s)<>s) then
19        msg = _("%s: Wrong type for input argument #%d: An integer matrix expected.\n")
20        error(msprintf(msg, "%p_j_s", 2))
21    end
22    [m,n] = size(p)
23    [ms,ns] = size(s)
24    if ms==1 & ns==1 then
25        if s<0 then
26            if or(abs(coeff(p(:)))*ones(max(0,max(degree(p)))+1,1)==0) then
27                msg = _("%s: Division by 0...\n")
28                error(msprintf(msg, "%p_j_s"))
29            end
30            f=rlist(ones(p),p.^(-s),[])
31        else // this case is in fact hard coded
32            f=p.^s
33        end
34    elseif m==1 & n==1 then // Element wise exponentiation p.^s with p "scalar"
35        kp=find(s>=0)
36        kn=find(s<0)
37        num=ones(s)
38        den=ones(s)
39        num(kp)=p.^s(kp)
40        p=1/p
41        num(kn)=p(2).^(-s(kn))
42        den(kn)=p(3).^(-s(kn))
43        f=rlist(num,den,[])
44    elseif ms==m & ns==n then  // Element wise exponentiation
45        p=p(:);s=s(:);
46        kp=find(s>=0)
47        kn=find(s<0)
48        num=p
49        den=ones(s)
50        num(kp)=num(kp).^s(kp)
51        if or(abs(coeff(p(kn)))*ones(max(0,max(degree(p(kn))))+1,1)==0) then
52            msg = _("%s: Division by 0...\n")
53            error(msprintf(msg, "%p_j_s"))
54        end
55        num(kn)=ones(p(kn))
56        den(kn)=p(kn).^(-s(kn))
57        f = rlist(matrix(num,n,m),matrix(den,n,m),[])
58    else
59        msg = _("%s: Arguments #%d and #%d: Incompatible sizes.\n")
60        error(msprintf(msg, "%p_j_s", 1, 2))
61    end
62
63endfunction
64