28f1b6c7d416172aacbb7a0e898a2ac39557c4aa
[scilab.git] / scilab / modules / overloading / macros / %r_a_r.sci
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
13 function f = %r_a_r(s1, s2)
14     if ndims(s1)<2 & ndims(s2)<2 then
15         [s1,s2] = sysconv(s1,s2)
16     end
17     [num1,den1] = s1(["num","den"])
18     [num2,den2] = s2(["num","den"])
19     sz1 = size(num1)
20     sz2 = size(num2)
21
22     if and(sz1>=0)&and(sz2>=0) then
23         num1 = num1(:)
24         den1 = den1(:)
25         num2 = num2(:)
26         den2 = den2(:)
27
28         if prod(sz1)==1 & prod(sz2)>1 then
29             den1 = den1(ones(den2))
30             num1 = num1(ones(num2))
31             sz1 = sz2
32         elseif prod(sz2)==1 & prod(sz1)>1 then
33             den2 = den2(ones(den1))
34             num2 = num2(ones(num1))
35             sz2 = sz1
36         end
37         if and(sz1<>sz2) then
38             error(8)
39         end
40         for l = 1:prod(sz1)
41             [den,fact] = lcm([den1(l); den2(l)])
42             num1(l) = [num1(l),num2(l)]*fact
43             den1(l) = den
44         end
45         [num1,den1] = simp(num1,den1)
46         f = rlist(matrix(num1,sz1),matrix(den1,sz1),s1.dt)
47     else
48         if size(sz1,"*")>2|size(sz2,"*")>2 then
49             error(8)
50         end
51         if or(sz1<0) & or(sz2<0) then
52             // both are eye*x
53             [den1,fact] = lcm([den1; den2])
54             [num1,den1] = simp([num1, num2]*fact, den1)
55             f = rlist(num1*eye(),den1*eye(),s1("dt"))
56         elseif or(sz1<0) then
57             den1 = den1+0
58             num1 = num1+0
59             for l = 1:min(sz2)
60                 [den,fact] = lcm([den1; den2(l,l)])
61                 num2(l,l) = [num1, num2(l,l)]*fact
62                 den2(l,l) = den
63             end
64             [num2,den2] = simp(num2, den2),
65             f = rlist(num2, den2, s1.dt)
66         elseif or(sz2<0) then
67             den2 = den2+0
68             num2 = num2+0
69             for l = 1:min(sz1)
70                 [den,fact] = lcm([den1(l,l); den2])
71                 num1(l,l) = [num1(l,l) num2]*fact
72                 den1(l,l) = den
73             end
74             [num1,den1] = simp(num1,den1)
75             f = rlist(num1, den1, s1.dt)
76         end
77     end
78     if simp_mode()
79         f = simp(f)
80     end
81 endfunction