File: time_id.sci

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (40 lines) | stat: -rw-r--r-- 838 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
function [h,err]=time_id(n,u,y)
// Copyright INRIA
[lhs,rhs]=argn(0)
y=y(:)
npt=size(y,'*');
select type(u)
case 1 then
  u=u(:)
case 10 then
  select part(u,1)
  case 'i' then
    u=eye(npt,1)
  case 's' then
    u=ones(npt,1)
  else
    error(' time_id: waiting for ''i'' or ''s'' ')
  end
else
  error(' time_id: waiting for ''i'' or ''s'' ')
end
if y(1)==0 then // strictly proper case
  m(npt-1,2*n)=0;
  for k=1:n,m(k:npt-1,[k k+n])=[-y(1:npt-k) u(1:npt-k)];end
  coef=m\y(2:npt);
  num=poly(coef(2*n:-1:n+1),'z','c');
  den=poly([coef(n:-1:1);1],'z','c');
else
  m(npt,2*n+2)=0;
  for k=1:n+1,m(k:npt,[k k+n+1])=[-y(1:npt-k+1) u(1:npt-k+1)];end
  coef=-m(:,2:$)\m(:,1)
  num=poly(coef(2*n+1:-1:n+1),'z','c');
  den=poly([coef(n:-1:1);1],'z','c');
end

h=syslin('d',num,den)

if lhs==2 then 
  err=norm(y-rtitr(num,den,u')',2)
end