File: lin.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (34 lines) | stat: -rw-r--r-- 1,204 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
function [a,b,c,d]=lin(sim,x0,u0)
//Syntaxes : sl=lin(sim,x0,u0)    or
//           [a,b,c,d]=lin(sim,x0,u0)
//
//linearization of the non-linear differential system [y,xdot]=sim(x,u)
//around x0 , u0. (sim is a scilab macro which computes y and xdot).
//output:
//- linear system sl (syslin list)
//- (a,b,c,d)
//
//  Example : Let ftz be the function passed to ode e.g.
//            [zd]=ftz(t,z,u), and let us assume y=x.
//            [z]=ode(x0,t0,tf,list(ftz,u) compute x(tf)
//            Let simula be the followinf function:
//            function [y,xd]=simula(x,u)
//            xd=ftz(tf,x,u); y=x;
//
//            The tangent linear system sl is obtained by:
//               [a,b,c,d]=lin(simula,z,u)
//                sl = syslin('c',a,b,c,d,x0)
//!
// Copyright INRIA
[lhs,rhs]=argn(0)
[n,w]=size(x0);[m,w]=size(u0);mpn=m+n
nrm=norm([x0;u0]);if nrm<1 then nrm=1,end;
[zz,nu]=colcomp(rand(mpn,mpn));
d=10*%eps*nrm*zz(:,1:nu); [y,xd]=sim(x0,u0); y0=[xd;y];
ab=[];for v=d,[y,xd]=sim(x0+v(1:n),u0+v(n+1:mpn)),
     ab=[ab,([xd;y]-y0)],end
[p,w]=size(y);
ab=ab/d;a=ab(1:n,1:n);b=ab(1:n,n+1:mpn)
c=ab(n+1:n+p,1:n);d=ab(n+1:n+p,n+1:mpn)
if lhs==1 then a=syslin('c',a,b,c,d,x0),end
endfunction