home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / r / rlab / CTB / xsi < prev    next >
Encoding:
Text File  |  1995-11-15  |  1.3 KB  |  72 lines

  1. //-------------------------------------------------------------------
  2. //
  3. // xsi
  4. //
  5. // Syntax: Si=xsi(ns,i)
  6. //
  7. // Computes the skew-symmetric basis matrix corresponding to
  8. // entry i for a ns x ns matrix.
  9. //
  10. // Si = [  0    1
  11. //               jk
  12. //         -1   0   ]
  13. //           jk
  14. // for j<>k
  15. //
  16. // The ith entry is counted across rows from the first upper 
  17. // diagonal location.
  18. //
  19. // This function is used in the optimal S=-S^* computation for
  20. // covariance control. (xsoptj)
  21. //
  22. // Originally written by L. D. Peterson
  23. // Modified by Jeff Layton and Ported to RLaB, 10/13/93
  24. //
  25. // Version JBL 931013
  26. //-------------------------------------------------------------------
  27.  
  28. xsi = function(ns,i)
  29. {
  30.    local(m,j,k,Si,icount)
  31.  
  32. // Begin with a full matrix of zeros
  33.  
  34.    Si=zeros(ns,ns);
  35.  
  36. // Number of skew-symmetric free parameters
  37.  
  38.    m=ns*(ns-1) / 2;
  39.    if ( i > m) {
  40.        error("i > m in xsi");
  41.    }
  42.    if (i == 0) {
  43.        error("i == 0 in xsi");
  44.    }
  45.  
  46. // Determine j and k by counting across rows 
  47.  
  48.    j=1;
  49.    k=2;
  50.  
  51.    for (icount in 1:m) {
  52.         if (icount == i)  {icount=2*m;}
  53.         if (k != ns) {
  54. //
  55. // Case 1: not at end of row
  56. //
  57.             k=k+1;
  58.         else
  59. //
  60. // Case 2: at end of row
  61. //
  62.             j=j+1;
  63.             k=j+1;
  64.         }
  65.    }
  66.  
  67.    Si[j;k]=1;
  68.    Si[k;j]=-1;
  69.  
  70.    return Si
  71. };
  72.