home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / meschach / !Meschach / c / submat < prev    next >
Encoding:
Text File  |  1994-01-13  |  4.4 KB  |  182 lines

  1. ;
  2.  
  3.     if ( ! A )
  4.         error(E_NULL,"bifactor");
  5.     if ( ( U && ( U->m != U->n ) ) || ( V && ( V->m != V->n ) ) )
  6.         error(E_SQUARE,"bifactor");
  7.     if ( ( U && U->m != A->m ) || ( V && V->m != A->n ) )
  8.         error(E_SIZES,"bifactor");
  9.     tmp1 = v_resize(tmp1,A->m);
  10.     tmp2 = v_resize(tmp2,A->n);
  11.     MEM_STAT_REG(tmp1,TYPE_VEC);
  12.     MEM_STAT_REG(tmp2,TYPE_VEC);
  13.  
  14.     if ( A->m >= A->n )
  15.         for ( k = 0; k < A->n; k++ )
  16.         {
  17.         get_col(A,k,tmp1);
  18.         hhvec(tmp1,k,&beta,tmp1,&(A->me[k][k]));
  19.         hhtrcols(A,k,k+1,tmp1,beta);
  20.         if ( U )
  21.             hhtrcols(U,k,0,tmp1,beta);
  22.         if ( k+1 >= A->n )
  23.             continue;
  24.         get_row(A,k,tmp2);
  25.         hhvec(tmp2,k+1,&beta,tmp2,&(A->me[k][k+1]));
  26.         hhtrrows(A,k+1,k+1,tmp2,beta);
  27.         if ( V )
  28.             hhtrcols(V,k+1,0,tmp2,beta);
  29.         }
  30.     else
  31.         for ( k = 0; k < A->m; k++ )
  32.         {
  33.         get_row(A,k,tmp2);
  34.         hhvec(tmp2,k,&beta,tmp2,&(A->me[k][k]));
  35.         hhtrrows(A,k+1,k,tmp2,beta);
  36.         if ( V )
  37.             hhtrcols(V,k,0,tmp2,beta);
  38.         if ( k+1 >= A->m )
  39.             continue;
  40.         get_col(A,k,tmp1);
  41.         hhvec(tmp1,k+1,&beta,tmp1,&(A->me[k+1][k]));
  42.         hhtrcols(A,k+1,k+1,tmp1,beta);
  43.         if ( U )
  44.             hhtrcols(U,k+1,0,tmp1,beta);
  45.         }
  46.  
  47.     return A;
  48. }
  49.  
  50. /* svd -- returns vector of singular values in d
  51.     -- also updates U and/or V, if one or the other is non-NULL
  52.     -- destroys A */
  53. VEC    *svd(A,U,V,d)
  54. MAT    *A, *U, *V;
  55. VEC    *d;
  56. {
  57.     static VEC    *f=VNULL;
  58.     int    i, limit;
  59.     MAT    *A_tmp;
  60.  
  61.     if ( ! A )
  62.         error(E_NULL,"svd");
  63.     if ( ( U && ( U->m != U->n ) ) || ( V && ( V->m != V->n ) ) )
  64.         error(E_SQUARE,"svd");
  65.     if ( ( U && U->m != A->m ) || ( V && V->m != A->n ) )
  66.         error(E_SIZES,"svd");
  67.  
  68.     A_tmp = m_copy(A,MNULL);
  69.     if ( U != MNULL )
  70.         m_ident(U);
  71.     if ( V != MNULL )
  72.         m_ident(V);
  73.     limit = min(A_tmp->m,A_tmp->n);
  74.     d = v_resize(d,limit);
  75.     f = v_resize(f,limit-1);
  76.     MEM_STAT_REG(f,TYPE_VEC);
  77.  
  78.     bifactor(A_tmp,U,V);
  79.     if ( A_tmp->m >= A_tmp->n )
  80.         for ( i = 0; i < limit; i++ )
  81.         {
  82.         d->ve[i] = A_tmp->me[i][i];
  83.         if ( i+1 < limit )
  84.             f->ve[i] = A_tmp->me[i][i+1];
  85.         }
  86.     else
  87.         for ( i = 0; i < limit; i++ )
  88.         {
  89.         d->ve[i] = A_tmp->me[i][i];
  90.         if ( i+1 < limit )
  91.             f->ve[i] = A_tmp->me[i+1][i];
  92.         }
  93.  
  94.  
  95.     if ( A_tmp->m >= A_tmp->n )
  96.         bisvd(d,f,U,V);
  97.     else
  98.         bisvd(d,f,V,U);
  99.  
  100.     M_FREE(A_tmp);
  101.  
  102.     return d;
  103. }
  104.  
  105. FileDataŵsymmeigOEÿÿÿüz¶(4¿
  106. /**************************************************************************
  107. **
  108. ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  109. **
  110. **                 Meschach Library
  111. ** 
  112. ** This Meschach Library is provided "as is" without any express 
  113. ** or implied warranty of any kind with respect to this software. 
  114. ** In particular the authors shall not be liable for any direct, 
  115. ** indirect, special, incidental or consequential damages arising 
  116. ** in any way from use of the software.
  117. ** 
  118. ** Everyone is granted permission to copy, modify and redistribute this
  119. ** Meschach Library, provided:
  120. **  1.  All copies contain this copyright notice.
  121. **  2.  All modified copies shall carry a notice stating who
  122. **      made the last modification and the date of such modification.
  123. **  3.  No charge is made for this software or works derived from it.  
  124. **      This clause shall not be construed as constraining other software
  125. **      distributed on the same medium as this software, nor is a
  126. **      distribution fee considered a charge.
  127. **
  128. ***************************************************************************/
  129.  
  130.  
  131. /*
  132.     File containing routines for symmetric eigenvalue problems
  133. */
  134.  
  135. #include    <stdio.h>
  136. #include    <math.h>
  137. #include    "matrix.h"
  138. #include        "matrix2.h"
  139.  
  140.  
  141. static char rcsid[] = "$Id: symmeig.c,v 1.5 1994/02/16 03:23:39 des Exp $";
  142.  
  143.  
  144.  
  145. #define    SQRT2    1.4142135623730949
  146. #define    sgn(x)    ( (x) >= 0 ? 1 : -1 )
  147.  
  148. /* trieig -- finds eigenvalues of symmetric tridiagonal matrices
  149.     -- matrix represented by a pair of vectors a (diag entries)
  150.         and b (sub- & super-diag entries)
  151.     -- eigenvalues in a on return */
  152. VEC    *trieig(a,b,Q)
  153. VEC    *a, *b;
  154. MAT    *Q;
  155. {
  156.     int    i, i_min, i_max, n, split;
  157.     Real    *a_ve, *b_ve;
  158.     Real    b_sqr, bk, ak1, bk1, ak2, bk2, z;
  159.     Real    c, c2, cs, s, s2, d, mu;
  160.  
  161.     if ( ! a || ! b )
  162.         error(E_NULL,"trieig");
  163.     if ( a->dim != b->dim + 1 || ( Q && Q->m != a->dim ) )
  164.         error(E_SIZES,"trieig");
  165.     if ( Q && Q->m != Q->n )
  166.         error(E_SQUARE,"trieig");
  167.  
  168.     n = a->dim;
  169.     a_ve = a->ve;        b_ve = b->ve;
  170.  
  171.     i_min = 0;
  172.     while ( i_min < n )        /* outer while loop */
  173.     {
  174.         /* find i_max to suit;
  175.             submatrix i_min..i_max should be irreducible */
  176.         i_max = n-1;
  177.         for ( i = i_min; i < n-1; i++ )
  178.             if ( b_ve[i] == 0.0 )
  179.             {    i_max = i;    break;    }
  180.         if ( i_max <= i_min )
  181.         {
  182.             /* prin