File: tf2des.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (47 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function [S]=tf2des(G,flag)
//[S]=tf2des(G) 
// Transfer function to descriptor form: S=list('d',A,B,C,D,E)
//  E*dx=A*x+B*u
//  y=C*x+D*u
//  with flag="withD" a maximal rank D matrix is returned
//!
// Copyright INRIA
[LHS,RHS]=argn(0);
if RHS==1 then flag=[];end
if RHS==2&flag<>"withD" then warning("tf2des: unknown flag");end
Num=G(2);Den=G(3);
%s=poly(0,varn(Den));
[n,m]=size(Num);
pol=zeros(n,m);pro=pol;
//        Pro = strictly proper part of G
//        Pol = polynomial part of G.
for l=1:n,
    for k=1:m,
      denlk=Den(l,k);
      [r,q]=pdiv(Num(l,k)+0*%s,denlk+0*%s);
      pol(l,k)=q;
      pro(l,k)=r/denlk;
    end;
end;
 
sp=tf2ss(pro);
D=zeros(Num);

if flag=="withD" then
  D=coeff(pol,0);pol=pol-D;
end;
spol=tf2ss(horner(pol,1/%s)/%s);

[n1,n1]=size(sp(2));
[n2,n2]=size(spol(2));
A=[sp(2),0*ones(n1,n2);
   0*ones(n2,n1),eye(n2,n2)];
E=[eye(n1,n1),0*ones(n1,n2);
   0*ones(n2,n1),spol(2)];
B=[sp(3);
   spol(3)];
C=[sp(4),-spol(4)];
S=tlist(['des','A','B','C','D','E'],A,B,C,D,E)