[comp.sources.amiga] v02i049: matlab - matrix laboratory, Part09/11

page@swan.ulowell.edu (Bob Page) (11/03/88)

Submitted-by: strovink%galaxy-43@afit-ab.arpa (Mark A. Strovink)
Posting-number: Volume 2, Issue 49
Archive-name: applications/matlab/help.2

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	help-2
# This archive created: Wed Nov  2 16:19:36 1988
cat << \SHAR_EOF > help-2
      FOR J = 1:N, V = A(:,J); ...  except J is also set here.                  
                                                                                
FUN   For matrix arguments  X , the  functions  SIN,  COS,  ATAN,               
      SQRT,  LOG,  EXP and X**p are computed using eigenvalues  D               
      and eigenvectors  V .  If  <V,D> =  EIG(X)   then   f(X)  =               
      V*f(D)/V  .   This method may give inaccurate results if  V               
      is badly conditioned.  Some idea of  the  accuracy  can  be               
      obtained by comparing  X**1  with  X .                                    
      For vector arguments,  the  function  is  applied  to  each               
      component.                                                                
                                                                                
HESS  Hessenberg form.  The Hessenberg form of a matrix  is  zero               
      below the first subdiagonal.  If the matrix is symmetric or               
      Hermitian,  the  form  is  tridiagonal.   <P,H>  =  HESS(A)               
      produces  a  unitary  matrix P and a Hessenberg matrix H so               
      that A = P*H*P'.  By itself, HESS(A) returns H.                           
                                                                                
HILB  Inverse Hilbert matrix.  HILB(N)  is the inverse of  the  N               
      by  N   matrix  with elements  1/(i+j-1), which is a famous               
      example of a badly conditioned matrix.  The result is exact               
      for  N  less than about 15, depending upon the computer.                  
                                                                                
IF    Conditionally execute statements.  Simple form...                         
      IF expression rop expression, statements                                  
      where rop is =, <, >, <=, >=, or  <>  (not  equal)  .   The               
      statements  are  executed  once if the indicated comparison               
      between the real parts of the first components of  the  two               
      expressions  is true, otherwise the statements are skipped.               
      Example.                                                                  
      IF ABS(I-J) = 1, A(I,J) = -1;                                             
      More complicated forms use END in the same way it  is  used               
      with FOR and WHILE and use ELSE as an abbreviation for END,               
      IF expression not rop expression .  Example                               
      FOR I = 1:N, FOR J = 1:N, ...                                             
         IF I = J, A(I,J) = 2; ELSE IF ABS(I-J) = 1, A(I,J) = -1; ...           
         ELSE A(I,J) = 0;                                                       
      An easier way to accomplish the same thing is                             
      A = 2*EYE(N);                                                             
      FOR I = 1:N-1, A(I,I+1) = -1; A(I+1,I) = -1;                              
                                                                                
IMAG  IMAG(X)  is the imaginary part of  X .                                    
                                                                                
INV   INV(X)  is the inverse of the square matrix  X .  A warning               
      message  is  printed  if   X   is  badly  scaled  or nearly               
      singular.                                                                 
                                                                                
KRON  KRON(X,Y) is the Kronecker tensor product of X and Y  .  It               
      is  also  denoted by X .*. Y . The result is a large matrix               
      formed by taking all possible products between the elements               
      of  X  and  those  of Y . For example, if X is 2 by 3, then               
      X .*. Y is                                                                
                                                                                
            < x(1,1)*Y  x(1,2)*Y  x(1,3)*Y                                      
              x(2,1)*Y  x(2,2)*Y  x(2,3)*Y >                                    
                                                                                
      The five-point discrete Laplacian for an n-by-n grid can be               
      generated by                                                              
                                                                                
            T = diag(ones(n-1,1),1);  T = T + T';  I = EYE(T);                  
            A = T.*.I + I.*.T - 4*EYE;                                          
                                                                                
      Just  in  case  they  might  be  useful,  MATLAB   includes               
      constructions called Kronecker tensor quotients, denoted by               
      X ./. Y and X .\. Y .  They are obtained by  replacing  the               
      elementwise multiplications in X .*. Y with divisions.                    
                                                                                
LINES An internal count is kept of the number of lines of  output               
      since  the  last  input.   Whenever this count approaches a               
      limit, the  user  is  asked  whether  or  not  to  suppress               
      printing  until the next input.  Initially the limit is 25.               
      LINES(N) resets the limit to N .                                          
                                                                                
LOAD  LOAD('file') retrieves all the variables from  the  file  .               
      See  FILE  and  SAVE for more details.  To prepare your own               
      file for LOADing, change the READs to WRITEs  in  the  code               
      given under SAVE.                                                         
                                                                                
LOG   LOG(X)  is the  natural  logarithm  of   X  .   See  FUN  .               
      Complex results are produced if  X  is not positive, or has               
      nonpositive eigenvalues.                                                  
                                                                                
LONG  Determine output format.   All  computations  are  done  in               
      complex arithmetic and double precision if it is available.               
      SHORT and  LONG  merely  switch  between  different  output               
      formats.                                                                  
      SHORT    Scaled fixed point format with about 5 digits.                   
      LONG     Scaled fixed point format with about 15 digits.                  
      SHORT E  Floating point format with about 5 digits.                       
      LONG E   Floating point format with about 15 digits.                      
      LONG Z   System dependent format, often hexadecimal.                      
                                                                                
LU    Factors from Gaussian elimination.  <L,U> = LU(X)  stores a               
      upper triangular matrix in  U  and a 'psychologically lower               
      triangular matrix', i.e. a product of lower triangular  and               
      permutation matrices, in L , so that  X = L*U .  By itself,               
      LU(X) returns the output from CGEFA .                                     
                                                                                
MACRO The macro facility involves text and inward pointing  angle               
      brackets.  If  STRING  is  the  source  text for any MATLAB               
      expression or statement, then                                             
            t = 'STRING';                                                       
      encodes the text as a vector of integers  and  stores  that               
      vector in  t .  DISP(t) will print the text and                           
            >t<                                                                 
      causes the text to be interpreted, either as a statement or               
      as a factor in an expression.  For example                                
            t = '1/(i+j-1)';                                                    
            disp(t)                                                             
            for i = 1:n, for j = 1:n, a(i,j) = >t<;                             
      generates the Hilbert matrix of order n.                                  
      Another example showing indexed text,                                     
            S = <'x = 3            '                                            
                 'y = 4            '                                            
                 'z = sqrt(x*x+y*y)'>                                           
            for k = 1:3, >S(k,:)<                                               
      It is necessary that the strings making up  the  "rows"  of               
      the "matrix"  S  have the same lengths.                                   
                                                                                
MAGIC Magic square.  MAGIC(N) is an N  by  N  matrix  constructed               
      from  the integers 1 through N**2 with equal row and column               
      sums.                                                                     
                                                                                
NORM  For matrices..                                                            
      NORM(X)  is the largest singular value of  X .                            
      NORM(X,1)  is the 1-norm of  X .                                          
      NORM(X,2)  is the same as NORM(X) .                                       
      NORM(X,'INF')  is the infinity norm of  X .                               
      NORM(X,'FRO')  is the F-norm, i.e.  SQRT(SUM(DIAG(X'*X))) .               
      For vectors..                                                             
      NORM(V,P) = (SUM(V(I)**P))**(1/P) .                                       
      NORM(V) = NORM(V,2) .                                                     
      NORM(V,'INF') = MAX(ABS(V(I))) .                                          
                                                                                
ONES  All ones.  ONES(N)  is an N by N matrix of ones.  ONES(M,N)               
      is an M by N matrix of ones .  ONES(A)  is the same size as               
      A  and all ones .                                                         
                                                                                
ORTH  Orthogonalization.   Q  =  ORTH(X)   is   a   matrix   with               
      orthonormal  columns,  i.e. Q'*Q = EYE, which span the same               
      space as the columns of  X .                                              
                                                                                
PINV  Pseudoinverse.  X = PINV(A) produces a matrix   X   of  the               
      same  dimensions as  A' so that  A*X*A = A , X*A*X = X  and               
      AX  and  XA  are Hermitian .  The computation is  based  on               
      SVD(A)  and  any  singular values less than a tolerance are               
      treated   as    zero.     The    default    tolerance    is               
      NORM(SIZE(A),'inf')*NORM(A)*EPS.   This  tolerance  may  be               
      overridden with X = PINV(A,tol).  See RANK.                               
                                                                                
PLOT  PLOT(X,Y) produces a plot of  the  elements  of  Y  against               
      those  of X . PLOT(Y) is the same as PLOT(1:n,Y) where n is               
      the  number  of   elements   in   Y   .    PLOT(X,Y,P)   or               
      PLOT(X,Y,p1,...,pk)  passes the optional parameter vector P               
      or scalars p1 through pk to the plot routine.  The  default               
      plot  routine  is a crude printer-plot. It is hoped that an               
      interface to local graphics equipment can be provided.                    
      An interesting example is                                                 
            t = 0:50;                                                           
            PLOT( t.*cos(t), t.*sin(t) )                                        
                                                                                
POLY  Characteristic polynomial.                                                
      If  A  is an N by N matrix, POLY(A) is a column vector with               
      N+1   elements   which   are   the   coefficients   of  the               
      characteristic polynomial,  DET(lambda*EYE - A) .                         
      If V is a vector, POLY(V) is a vector  whose  elements  are               
      the  coefficients  of  the  polynomial  whose roots are the               
      elements of V .  For vectors, ROOTS and  POLY  are  inverse               
      functions  of  each  other,  up  to  ordering, scaling, and               
      roundoff error.                                                           
      ROOTS(POLY(1:20)) generates Wilkinson's famous example.                   
                                                                                
PRINT PRINT('file',X) prints X on  the  file  using  the  current               
      format determined by SHORT, LONG Z, etc.  See FILE.                       
                                                                                
PROD  PROD(X)  is the product of all the elements of  X .                       
                                                                                
QR    Orthogonal-triangular decomposition.                                      
      <Q,R> = QR(X)  produces an upper triangular  matrix   R  of               
      the  same dimension as  X  and a unitary matrix  Q  so that               
      X = Q*R .                                                                 
      <Q,R,E> = QR(X)  produces a  permutation  matrix   E  ,  an               
      upper  triangular  R  with decreasing diagonal elements and               
      a unitary  Q  so that  X*E = Q*R .                                        
      By itself, QR(X) returns the output of CQRDC .  TRIU(QR(X))               
      is R .                                                                    
                                                                                
RAND  Random numbers and matrices.  RAND(N)  is an N by N  matrix               
      with  random  entries.  RAND(M,N)  is an M by N matrix with               
      random entries.  RAND(A)  is the same size as   A  .   RAND               
      with no arguments is a scalar whose value changes each time               
      it is referenced.                                                         
      Ordinarily,  random numbers are  uniformly  distributed  in               
      the  interval  (0.0,1.0)  .   RAND('NORMAL')  switches to a               
      normal distribution  with  mean  0.0  and  variance  1.0  .               
      RAND('UNIFORM')  switches back to the uniform distribution.               
      RAND('SEED') returns the current value of the seed for  the               
      generator.    RAND('SEED',n)   sets   the   seed   to  n  .               
      RAND('SEED',0) resets the seed to 0, its value when  MATLAB               
      is first entered.                                                         
                                                                                
RANK  Rank.  K = RANK(X) is the number of singular values  of   X               
      that are larger than NORM(SIZE(X),'inf')*NORM(X)*EPS.                     
      K = RANK(X,tol) is the number of singular values of  X that               
      are larger than tol .                                                     
                                                                                
RCOND RCOND(X)   is  an  estimate  for  the  reciprocal  of   the               
      condition  of   X   in  the  1-norm obtained by the LINPACK               
      condition estimator.  If  X  is well conditioned,  RCOND(X)               
      is  near  1.0  .   If  X  is badly conditioned, RCOND(X) is               
      near 0.0 .                                                                
      <R, Z> = RCOND(A) sets  R  to RCOND(A) and also produces  a               
      vector  Z so that                                                         
                 NORM(A*Z,1) = R*NORM(A,1)*NORM(Z,1)                            
      So, if RCOND(A) is small, then  Z  is an  approximate  null               
      vector.                                                                   
                                                                                
RAT   An experimental  function  which  attempts  to  remove  the               
      roundoff   error  from  results  that  should  be  "simple"               
      rational numbers.                                                         
      RAT(X) approximates each  element  of   X  by  a  continued               
      fraction of the form                                                      
                                                                                
                a/b = d1 + 1/(d2 + 1/(d3 + ... + 1/dk))                         
                                                                                
      with k <= len, integer di and abs(di) <= max .  The default               
      values of the parameters are len = 5 and max = 100.                       
      RAT(len,max) changes the default values.  Increasing either               
      len or max increases the number of possible fractions.                    
      <A,B> = RAT(X) produces integer matrices A and B so that                  
                                                                                
                A ./ B  =  RAT(X)                                               
                                                                                
      Some examples:                                                            
                                                                                
            long                                                                
            T = hilb(6), X = inv(T)                                             
            <A,B> = rat(X)                                                      
            H = A ./ B, S = inv(H)                                              
                                                                                
            short e                                                             
            d = 1:8,  e = ones(d),  A = abs(d'*e - e'*d)                        
            X = inv(A)                                                          
            rat(X)                                                              
            display(ans)                                                        
                                                                                
                                                                                
REAL  REAL(X)  is the real part of  X .                                         
                                                                                
RETURN  From the terminal, causes return to the operating  system               
      or  other  program  which  invoked  MATLAB.  From inside an               
      EXEC, causes  return  to  the  invoking  EXEC,  or  to  the               
      terminal.                                                                 
                                                                                
RREF  RREF(A) is the reduced row echelon form of the  rectangular               
      matrix.  RREF(A,B) is the same as RREF(<A,B>) .                           
                                                                                
ROOTS Find polynomial roots.  ROOTS(C)  computes the roots of the               
      polynomial  whose  coefficients  are  the  elements  of the               
      vector  C .  If  C  has  N+1  components, the polynomial is               
      C(1)*X**N + ... + C(N)*X + C(N+1) .  See POLY.                            
                                                                                
ROUND ROUND(X)  rounds  the  elements  of   X   to  the   nearest               
      integers.                                                                 
                                                                                
SAVE  SAVE('file') stores all the current variables in a file.                  
      SAVE('file',X) saves only X .  See FILE .                                 
      The variables may be retrieved later by LOAD('file') or  by               
      your  own program using the following code for each matrix.               
      The lines involving XIMAG may be eliminated  if  everything               
      is known to be real.                                                      
                                                                                
            attach lunit to 'file'                                              
            REAL or DOUBLE PRECISION XREAL(MMAX,NMAX)                           
            REAL or DOUBLE PRECISION XIMAG(MMAX,NMAX)                           
            READ(lunit,101) ID,M,N,IMG                                          
            DO 10 J = 1, N                                                      
               READ(lunit,102) (XREAL(I,J), I=1,M)                              
               IF (IMG .NE. 0) READ(lunit,102) (XIMAG(I,J),I=1,M)               
         10 CONTINUE                                                            
                                                                                
      The formats used are system dependent.  The  following  are               
      typical.     See    SUBROUTINE   SAVLOD   in   your   local               
      implementation of MATLAB.                                                 
                                                                                
        101 FORMAT(4A1,3I4)                                                     
        102 FORMAT(4Z18)                                                        
        102 FORMAT(4O20)                                                        
        102 FORMAT(4D25.18)                                                     
                                                                                
SCHUR Schur decomposition.  <U,T> = SCHUR(X)  produces  an  upper               
      triangular  matrix   T , with the eigenvalues of  X  on the               
      diagonal, and a unitary matrix  U so that  X =  U*T*U'  and               
      U'*U = EYE .  By itself, SCHUR(X) returns  T .                            
                                                                                
SHORT See LONG .                                                                
                                                                                
SEMI  Semicolons at the end of  lines  will  cause,  rather  than               
      suppress,  printing.   A  second  SEMI restores the initial               
      interpretation.                                                           
                                                                                
SIN   SIN(X)  is the sine of  X .  See FUN .                                    
                                                                                
SIZE  If X is an M by N matrix, then SIZE(X) is <M, N> .                        
      Can also be used with a multiple assignment,                              
            <M, N> = SIZE(X) .                                                  
                                                                                
SQRT  SQRT(X)  is the square root of  X .   See  FUN  .   Complex               
      results  are  produced  if   X   is  not  positive,  or has               
      nonpositive eigenvalues.                                                  
                                                                                
STOP  Use EXIT instead.                                                         
                                                                                
SUM   SUM(X)   is  the  sum  of  all  the  elements   of    X   .               
      SUM(DIAG(X))  is the trace of  X .                                        
                                                                                
SVD   Singular value decomposition.  <U,S,V> = SVD(X)  produces a               
      diagonal  matrix  S , of the same dimension as  X  and with               
      nonnegative diagonal  elements  in  decreasing  order,  and               
      unitary matrices  U  and  V  so that  X = U*S*V' .                        
      By itself, SVD(X) returns a vector containing the  singular               
      values.                                                                   
      <U,S,V>   =   SVD(X,0)   produces   the   "economy    size"               
      decomposition.   If  X  is m by n with m > n, then only the               
      first n columns of U are computed and S is n by n .                       
                                                                                
TRIL  Lower triangle.  TRIL(X) is the lower triangular part of X.               
      TRIL(X,K) is the elements on and below the K-th diagonal of               
      X.  K = 0 is the main diagonal, K > 0  is  above  the  main               
      diagonal and K < 0 is below the main diagonal.                            
                                                                                
TRIU  Upper triangle.  TRIU(X) is the upper triangular part of X.               
      TRIU(X,K) is the elements on and above the K-th diagonal of               
      X.  K = 0 is the main diagonal, K > 0  is  above  the  main               
      diagonal and K < 0 is below the main diagonal.                            
                                                                                
USER  Allows personal  Fortran  subroutines  to  be  linked  into               
      MATLAB .  The subroutine should have the heading                          
                                                                                
               SUBROUTINE USER(A,M,N,S,T)                                       
               REAL or DOUBLE PRECISION A(M,N),S,T                              
                                                                                
      The MATLAB statement  Y = USER(X,s,t)  results in a call to               
      the  subroutine with a copy of the matrix  X  stored in the               
      argument  A , its column and row dimensions in  M  and  N ,               
      and  the scalar parameters  s  and  t  stored in  S  and  T               
      . If  s and t  are omitted, they are set to  0.0  .   After               
      the  return,   A  is stored in  Y .  The dimensions  M  and               
      N  may be reset within the subroutine.  The statement  Y  =               
      USER(K)  results in a call with M = 1, N = 1  and  A(1,1) =               
      FLOAT(K) .  After the subroutine has been written, it  must               
      be compiled and linked to the MATLAB object code within the               
      local operating system.                                                   
                                                                                
WHAT  Lists commands and functions currently available.                         
                                                                                
WHILE Repeat statements an indefinite number of times.                          
      WHILE expr rop expr, statement, ..., statement, END                       
      where rop is =, <, >, <=, >=, or <> (not equal) .  The  END               
      at  the end of a line may be omitted.  The comma before the               
      END may also be omitted.  The commas  may  be  replaced  by               
      semicolons   to   avoid   printing.    The  statements  are               
      repeatedly executed as long  as  the  indicated  comparison               
      between  the  real parts of the first components of the two               
      expressions is true.   Example  (assume  a  matrix   A   is               
      already defined).                                                         
      E = 0*A; F = E + EYE; N = 1;                                              
      WHILE NORM(E+F-E,1) > 0, E = E + F; F = A*F/N; N = N + 1;                 
      E                                                                         
                                                                                
WHO   Lists current variables.                                                  
                                                                                
WHY   Provides succinct answers to any questions.                               
                                                                                
//                                                                              
SHAR_EOF
#	End of shell archive
exit 0
-- 
Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
Have five nice days.