summaryrefslogtreecommitdiff
path: root/modules/cacsd/macros/gtild.sci
diff options
context:
space:
mode:
authorShashank2017-05-29 12:40:26 +0530
committerShashank2017-05-29 12:40:26 +0530
commit0345245e860375a32c9a437c4a9d9cae807134e9 (patch)
treead51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/cacsd/macros/gtild.sci
downloadscilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip
CMSCOPE changed
Diffstat (limited to 'modules/cacsd/macros/gtild.sci')
-rwxr-xr-xmodules/cacsd/macros/gtild.sci111
1 files changed, 111 insertions, 0 deletions
diff --git a/modules/cacsd/macros/gtild.sci b/modules/cacsd/macros/gtild.sci
new file mode 100755
index 000000000..037a532e9
--- /dev/null
+++ b/modules/cacsd/macros/gtild.sci
@@ -0,0 +1,111 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA -
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+function Gt=gtild(G,flag)
+ // input:
+ // G(s): a polynomial matrix or a rational matrix
+ // represented in state-space or in transfer form
+ //
+ // Gt=gtild(G) or Gt=gtild(G,'c')
+ // returns Gt = G(-s)' (in transfer form or in state-space)
+ // for continuous time system G
+ //or
+ // Gt=gtild(G) or Gt=gtild(G,'d')
+ // returns Gt = z^n * G(1/z)' (n = maximum degree of G)
+ // for discrete-time matrix polynomials
+ //!
+
+ [lhs,rhs]=argn(0)
+ if rhs==1 then
+ if typeof(G)=="rational"
+ flag=G(4)
+ elseif typeof(G)=="state-space"
+ flag=G(7)
+ elseif typeof(G)=="polynomial"
+ flag=[]
+ end
+ end
+
+ select typeof(G)
+ case "polynomial"
+ if flag=="c"
+ Gt=cp_tilde(G);return;
+ elseif flag=="d"
+ Gt=dp_tilde(G);return;
+ elseif flag==[]
+ error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+ "gtild",2,"''c'', ''d''"));
+ end
+
+ case "rational"
+ v=varn([G(2),G(3)]);s=poly(0,v);
+ if flag=="c"
+ Gt=horner(G',-s);return;
+ elseif flag=="d"
+ Gt=horner(G',1/s);return;
+ elseif flag==[]
+ error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+ "gtild",2,"''c'', ''d''"));
+ end
+
+ case "state-space"
+ if flag==[] then dom=G(7);else dom=flag;end
+ [A,B,C,D]=abcd(G);
+ if dom=="c" then
+ if typeof(D)=="polynomial"
+ Dp=horner(D,-poly(0,varn(D)));
+ Gt=syslin(dom,-A',-C',B',Dp');return;
+ elseif typeof(D)=="constant"
+ Gt=syslin(dom,-A',-C',B',D');return
+ end
+ elseif dom=="d"
+ if typeof(G(5))=="polynomial"
+ Dp=horner(D,1/poly(0,varn(D)));
+ Dp=tf2ss(Dp);
+ [A,B,C,D]=abcd(G');
+ w=tlist(["des","A","B","C","D","E"],eye(A),B,C,0*C*B,A);
+ z=poly(0,"z");zss=-tf2ss(z);zss(7)="d";
+ Gt=zss*des2ss(w)+Dp';
+ elseif typeof(G(5))=="constant"
+ z=poly(0,"z");zss=-tf2ss(z);zss(7)="d";
+ [A,B,C,D]=abcd(G'); //lazy way for transposition...
+ w=tlist(["des","A","B","C","D","E"],eye(A),B,C,0*D,A);
+ Gt=zss*des2ss(w)+D; //-z*C*inv(I-z*A)*B + D
+ end
+ end
+ //
+ case "constant"
+ Gt=G';return;
+ end
+
+
+
+endfunction
+function mpt=dp_tilde(mp)
+ //mp(z) = polynomial matrix
+ // mpt(i,j)= z^n*conj(mp(j,i))(1/z)
+ [m,n]=size(mp),z=varn(mp)
+ //max degree
+ nmax=max(degree(mp));
+ for i=1:m
+ for j=1:n
+ mpt(j,i)=poly(coeff(conj(mp(i,j)),nmax:-1:0),z,"c")
+ end
+ end
+
+endfunction
+function mpt=cp_tilde(mp)
+ //mp(s) = polynomial matrix
+ // mpt(i,j)= conj(mp(j,i))(s)
+ s=poly(0,varn(mp));
+ pr=real(mp);pi=imag(mp);
+ mpt=horner(pr',-s);
+ if pi==0*s then return;end
+ mpt=mpt+%i*horner(pi',-s);
+endfunction