~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to macros/util/lin.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [a,b,c,d]=lin(sim,x0,u0)
 
2
//Syntaxes : sl=lin(sim,x0,u0)    or
 
3
//           [a,b,c,d]=lin(sim,x0,u0)
 
4
//
 
5
//linearization of the non-linear differential system [y,xdot]=sim(x,u)
 
6
//around x0 , u0. (sim is a scilab macro which computes y and xdot).
 
7
//output:
 
8
//- linear system sl (syslin list)
 
9
//- (a,b,c,d)
 
10
//
 
11
//  Example : Let ftz be the function passed to ode e.g.
 
12
//            [zd]=ftz(t,z,u), and let us assume y=x.
 
13
//            [z]=ode(x0,t0,tf,list(ftz,u) compute x(tf)
 
14
//            Let simula be the followinf function:
 
15
//            function [y,xd]=simula(x,u)
 
16
//            xd=ftz(tf,x,u); y=x;
 
17
//
 
18
//            The tangent linear system sl is obtained by:
 
19
//               [a,b,c,d]=lin(simula,z,u)
 
20
//                sl = syslin('c',a,b,c,d,x0)
 
21
//!
 
22
// Copyright INRIA
 
23
[lhs,rhs]=argn(0)
 
24
[n,w]=size(x0);[m,w]=size(u0);mpn=m+n
 
25
nrm=norm([x0;u0]);if nrm<1 then nrm=1,end;
 
26
[zz,nu]=colcomp(rand(mpn,mpn));
 
27
d=10*%eps*nrm*zz(:,1:nu); [y,xd]=sim(x0,u0); y0=[xd;y];
 
28
ab=[];for v=d,[y,xd]=sim(x0+v(1:n),u0+v(n+1:mpn)),
 
29
     ab=[ab,([xd;y]-y0)],end
 
30
[p,w]=size(y);
 
31
ab=ab/d;a=ab(1:n,1:n);b=ab(1:n,n+1:mpn)
 
32
c=ab(n+1:n+p,1:n);d=ab(n+1:n+p,n+1:mpn)
 
33
if lhs==1 then a=syslin('c',a,b,c,d,x0),end
 
34
 
 
35
 
 
36