howto/use this wiki/wikiparser scilab - Scilab Wiki

Colorized source displays for scilab scripts

scripts

   1 function [xr,yr,zr,xi,yi,zi] = CmplxFacets(R,e,TypeDomain,TypeCut,n,StrFunc)
   2 
   3         //  A function to compute the facets for drawing a complex function
   4         //  on a square or a disk with branch(es) cut(s) on Ox or Oy
   5         //
   6         //  TypeDomain : "Square" or "Disk"
   7         //     TypeCut : "Ox" or "Oy"
   8         //           R : length of half a side of the square or radius of the disk
   9         //           e : thin layer to avoid the branch(es) cut(s)
  10         //           n : a scalar (for Square) or a 2-vector = [ntheta, nr]
  11         //               (for Disk) for discretization
  12         //     StrFunc : the string which names the complex function (this is
  13         //               because primitive don't pass as function argument)
  14         
  15         if TypeDomain == "Square" then
  16                 if TypeCut == "Ox" then
  17                         x1 = linspace(-R, R, n);
  18                         y1 = linspace( e, R, n/2);
  19                 else  // for TypeCut = "Oy" ...
  20                         x1 = linspace( e, R, n/2);
  21                         y1 = linspace(-R, R, n);
  22                 end
  23                 X1 = ones(y1')*x1 ; Y1 = y1'*ones(x1);
  24         else // for TypeDomain = "Disk"
  25                 r = linspace(0,R, n(2));
  26                 if TypeCut == "Ox" then
  27                         theta = linspace(0,%pi,n(1))';
  28                         X1 = cos(theta)*r;
  29                         Y1 = e + sin(theta)*r;
  30                 else // for TypeCut = "Oy"
  31                         theta = linspace(-%pi/2,%pi/2,n(1))';
  32                         X1 = e + cos(theta)*r;
  33                         Y1 = sin(theta)*r;
  34                 end
  35         end
  36         X2 = -X1 ; Y2 = -Y1;
  37         Z1 = evstr(StrFunc+"(X1 + %i*Y1)");
  38         Z2 = evstr(StrFunc+"(X2 + %i*Y2)");
  39         [xr1,yr1,zr1] = nf3d(X1,Y1,real(Z1));
  40         [xr2,yr2,zr2] = nf3d(X2,Y2,real(Z2));
  41         xr = [xr1 xr2]; yr = [yr1 yr2]; zr = [zr1 zr2];
  42         [xi1,yi1,zi1] = nf3d(X1,Y1,imag(Z1));
  43         [xi2,yi2,zi2] = nf3d(X2,Y2,imag(Z2));
  44         xi = [xi1 xi2]; yi = [yi1 yi2]; zi = [zi1 zi2];
  45 endfunction 

console output

   1 
   2 -->A=diag([2,3,4]);B=[1 0;0 1;0 0];C=[1 -1 0];D=0*C*B;x0=[0;0;0];
   3 
   4 -->Sl=syslin('c',A,B,C,D,x0)    //Standard state-space linear system
   5  Sl  =
   6  
   7  
   8        Sl(1)   (state-space system:)
   9  
  10 !lss  A  B  C  D  X0  dt  !
  11  
  12        Sl(2) = A matrix = 
  13  
  14     2.    0.    0.  
  15     0.    3.    0.  
  16     0.    0.    4.  
  17  
  18        Sl(3) = B matrix = 
  19  
  20     1.    0.  
  21     0.    1.  
  22     0.    0.  
  23  
  24        Sl(4) = C matrix = 
  25  
  26     1.  - 1.    0.  
  27  
  28        Sl(5) = D matrix = 
  29  
  30     0.    0.  
  31  
  32        Sl(6) = X0 (initial state) = 
  33  
  34     0.  
  35     0.  
  36     0.  
  37  
  38        Sl(7) = Time domain = 
  39  c
  40  
  41 -->Sl("A"), Sl("C")             //Retrieving elements of a typed list
  42  ans  =
  43  
  44     2.    0.    0.  
  45     0.    3.    0.  
  46     0.    0.    4.  
  47  ans  =
  48  
  49     1.  - 1.    0.  
  50 
  51 -->Slt=ss2tf(Sl)                // Transfer matrix
  52  Slt  =
  53  
  54       1       - 1     
  55     -----     -----   
  56   - 2 + s   - 3 + s   
  57 
  58 -->Slt('num'), Slt('den')
  59  ans  =
  60  
  61     1   - 1   
  62  ans  =
  63  
  64   - 2 + s   - 3 + s   

howto/use this wiki/wikiparser scilab (last edited 2009-03-18 08:41:28 by pmarecha)