summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorSamuel GOUGEON <sgougeon@free.fr>2021-04-23 21:14:19 +0200
committerClement DAVID <clement.david@esi-group.com>2021-04-29 11:32:50 +0200
commit1dd7bd3cd6eda59db710af5251bd44eca2318a43 (patch)
treeed462442fd10a5729479e9cd8371ee2e134fc4e4 /scilab
parent3b3f272ee6e0d85b2f3000a3648e12cd2785bed8 (diff)
downloadscilab-1dd7bd3cd6eda59db710af5251bd44eca2318a43.zip
scilab-1dd7bd3cd6eda59db710af5251bd44eca2318a43.tar.gz
%p_s_r, %r_s_p, %r_a_p, %r_x_p: simplify duplicate codes
Change-Id: I7a3b6ad7a113a88ba23da3fe8e978618f178b14f
Diffstat (limited to 'scilab')
-rw-r--r--scilab/modules/overloading/macros/%p_a_r.sci3
-rw-r--r--scilab/modules/overloading/macros/%p_s_r.sci38
-rw-r--r--scilab/modules/overloading/macros/%r_a_p.sci42
-rw-r--r--scilab/modules/overloading/macros/%r_s_p.sci39
-rw-r--r--scilab/modules/overloading/macros/%r_x_p.sci19
5 files changed, 16 insertions, 125 deletions
diff --git a/scilab/modules/overloading/macros/%p_a_r.sci b/scilab/modules/overloading/macros/%p_a_r.sci
index 8126f9d..8ed93a3 100644
--- a/scilab/modules/overloading/macros/%p_a_r.sci
+++ b/scilab/modules/overloading/macros/%p_a_r.sci
@@ -33,7 +33,8 @@ function f=%p_a_r(m,f)
33 else 33 else
34 //at leat one matrix is eye*x 34 //at leat one matrix is eye*x
35 if size(szf,"*")>2 | size(szm,"*")>2 then 35 if size(szf,"*")>2 | size(szm,"*")>2 then
36 error(msprintf(_("%s: Inconsistent addition.\n"), "%p_a_r")) 36 msg = gettext("%s: Eye variable undefined in this context.\n")
37 error(msprintf(msg, "%p_a_r"));
37 end 38 end
38 if or(szf<0)&or(szm<0) then 39 if or(szf<0)&or(szm<0) then
39 [num,den]=simp(num+m.*den,den) 40 [num,den]=simp(num+m.*den,den)
diff --git a/scilab/modules/overloading/macros/%p_s_r.sci b/scilab/modules/overloading/macros/%p_s_r.sci
index ead17f0..a1cf4be 100644
--- a/scilab/modules/overloading/macros/%p_s_r.sci
+++ b/scilab/modules/overloading/macros/%p_s_r.sci
@@ -1,7 +1,7 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA 2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises 3// Copyright (C) 2012 - 2016 - Scilab Enterprises
4// Copyright (C) 2021 - Samuel GOUGEON
5// 5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0, 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. 7// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -11,38 +11,6 @@
11// along with this program. 11// along with this program.
12 12
13function f = %p_s_r(m,f) 13function f = %p_s_r(m,f)
14 //f= m-f 14 f = m + (-f)
15 //author Serge Steer INRIA 15 // see %p_a_r()
16 //!
17 [num,den]=f(["num","den"])
18 szf=size(den)
19 szm=size(m)
20
21 if and(szf>=0)&and(szm>=0) then
22 if prod(szf)==1&prod(szm)>1 then
23 den=den(ones(m))
24 szf=szm
25 end
26
27 if size(szf,"*")>2 then
28 num=num(:);den=den(:);m=m(:)
29 end
30 [num,den]=simp(-num+m.*den,den)
31 num=matrix(num,szf)
32 den=matrix(den,szf)
33 else
34 //at leat one matrix is eye*x
35 if size(szf,"*")>2 | size(szm,"*")>2 then
36 msg = gettext("%s: Eye variable undefined in this context.\n")
37 error(msprintf(msg, "%p_s_r"));
38 end
39 if or(szf<0)&or(szm<0) then
40 [num,den]=simp(-num+m.*den,den)
41 elseif or(szf<0) then
42 [num,den]=simp(-num+m.*den,den*ones(m))
43 elseif or(szm<0) then
44 [num,den]=simp(-num+(m+0)*eye(den).*den,den)
45 end
46 end
47 f=rlist(num,den,f.dt)
48endfunction 16endfunction
diff --git a/scilab/modules/overloading/macros/%r_a_p.sci b/scilab/modules/overloading/macros/%r_a_p.sci
index 03137e1..46be8d9 100644
--- a/scilab/modules/overloading/macros/%r_a_p.sci
+++ b/scilab/modules/overloading/macros/%r_a_p.sci
@@ -1,7 +1,7 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA 2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises 3// Copyright (C) 2012 - 2016 - Scilab Enterprises
4// Copyright (C) 2021 - Samuel GOUGEON
5// 5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0, 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. 7// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -10,41 +10,7 @@
10// For more information, see the COPYING file which you should have received 10// For more information, see the COPYING file which you should have received
11// along with this program. 11// along with this program.
12 12
13function f=%r_a_p(f,m) 13function f = %r_a_p(f,m)
14 //f = f+m, 14 f = m + f
15 //f: transfer matrix, m : polynomial matrix 15 // see %p_a_r()
16 //author Serge Steer INRIA
17 //!
18 [num,den]=f(["num","den"])
19 szf=size(den)
20 szm=size(m)
21
22 if and(szf>=0)&and(szm>=0) then
23 if prod(szf)==1&prod(szm)>1 then
24 den=den(ones(m))
25 szf=szm
26 end
27
28 if size(szf,"*")>2 then
29 num=num(:);den=den(:);m=m(:)
30 end
31 [num,den]=simp(num+m.*den,den)
32 num=matrix(num,szf)
33 den=matrix(den,szf)
34 else
35 //at leat one matrix is eye*x
36 if size(szf,"*")>2 | size(szm,"*")>2 then
37 msg = _("%s: Inconsistent addition.\n")
38 error(msprintf(msg, "%r_a_p"))
39 end
40 if or(szf<0)&or(szm<0) then
41 [num,den]=simp(num+m.*den,den)
42 elseif or(szf<0) then
43 [num,den]=simp(num+m.*den,den*ones(m))
44 elseif or(szm<0) then
45 [num,den]=simp(num+(m+0)*eye(den).*den,den)
46 end
47 end
48 f=rlist(num,den,f.dt)
49
50endfunction 16endfunction
diff --git a/scilab/modules/overloading/macros/%r_s_p.sci b/scilab/modules/overloading/macros/%r_s_p.sci
index f465616..51d37a5 100644
--- a/scilab/modules/overloading/macros/%r_s_p.sci
+++ b/scilab/modules/overloading/macros/%r_s_p.sci
@@ -1,7 +1,7 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA 2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises 3// Copyright (C) 2012 - 2016 - Scilab Enterprises
4// Copyright (C) 2021 - Samuel GOUGEON
5// 5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0, 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. 7// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -11,39 +11,6 @@
11// along with this program. 11// along with this program.
12 12
13function f = %r_s_p(f,m) 13function f = %r_s_p(f,m)
14 //f = f-m, 14 f = f + (-m)
15 //f: transfer matrix, m : scalar or scalar matrix 15 // see %r_a_p
16 //author Serge Steer INRIA
17 //!
18 [num,den]=f(["num","den"])
19 szf=size(den)
20 szm=size(m)
21
22 if and(szf>=0)&and(szm>=0) then
23 if prod(szf)==1&prod(szm)>1 then
24 den=den(ones(m))
25 szf=szm
26 end
27
28 if size(szf,"*")>2 then
29 num=num(:);den=den(:);m=m(:)
30 end
31 [num,den]=simp(num-m.*den,den)
32 num=matrix(num,szf)
33 den=matrix(den,szf)
34 else
35 //at leat one matrix is eye*x
36 if size(szf,"*")>2 | size(szm,"*")>2 then
37 msg = gettext("%s: Eye variable undefined in this context.\n")
38 error(msprintf(msg, "%r_s_p"));
39 end
40 if or(szf<0)&or(szm<0) then
41 [num,den]=simp(num-m.*den,den)
42 elseif or(szf<0) then
43 [num,den]=simp(num-m.*den,den*ones(m))
44 elseif or(szm<0) then
45 [num,den]=simp(num-(m+0)*eye(den).*den,den)
46 end
47 end
48 f=rlist(num,den,f.dt)
49endfunction 16endfunction
diff --git a/scilab/modules/overloading/macros/%r_x_p.sci b/scilab/modules/overloading/macros/%r_x_p.sci
index 428ce9f..7abdacd 100644
--- a/scilab/modules/overloading/macros/%r_x_p.sci
+++ b/scilab/modules/overloading/macros/%r_x_p.sci
@@ -1,7 +1,7 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA 2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises 3// Copyright (C) 2012 - 2016 - Scilab Enterprises
4// Copyright (C) 2021 - Samuel GOUGEON
5// 5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0, 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. 7// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -10,18 +10,7 @@
10// For more information, see the COPYING file which you should have received 10// For more information, see the COPYING file which you should have received
11// along with this program. 11// along with this program.
12 12
13function f1=%r_x_p(f1,f2) 13function f1 = %r_x_p(f1, f2)
14 // %r_x_p(r,p)=r.*p 14 // rat .* pol == pol .* rat
15 //author Serge Steer, INRIA 15 f1 = %p_x_r(f2, f1)
16 //!
17 f1.num=f1.num.*f2
18 sz=size(f1.num)
19 if size(sz,"*")<=2 then
20
21 f1=simp(f1)
22 else
23 [num,den]=simp(f1.num(:),f1.den(:))
24 f1.num=matrix(num,sz)
25 f1.den=matrix(den,sz)
26 end
27endfunction 16endfunction