home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / rlab1_23a / CTB / singsen < prev    next >
Text File  |  1995-11-14  |  1KB  |  57 lines

  1. //------------------------------------------------------------------------------
  2. //
  3. // singsen
  4. //
  5. // Syntax: D=singsen(A,dAdp)
  6. //
  7. // This routine computes the partial derivative of the singular values
  8. // of a matrix with respect to a scalar parameter. All that is needed
  9. // is the matrix and the partial of the matrix with respect to a parameter
  10. // p ( d(A)/dp ).
  11. //
  12. // The routine returns a column vector containing the partial derivatives
  13. // of the singular values of the matrix A which has a gradient of d(A)/dp.
  14. // This routine computes the partial derivative of the singular values
  15. //
  16. //  Ref. Chapter 2 of Junkins and Kim, Dyn and Control of Flex. Structures
  17. //
  18. // Copyright (C), by Jeffrey B. Layton, 1994
  19. // Version JBL 931120
  20. //------------------------------------------------------------------------------
  21.  
  22. singsen = function(A,dAdp)
  23. {
  24.    local(nargs,Adum,U,S,V,n,svsen,Acheck,Aerr,i)
  25.  
  26. // Count number of input arguments
  27.    nargs=0;
  28.    if (exist(A)) {nargs=nargs+1;}
  29.    if (exist(dAdp)) {nargs=nargs+1;}
  30.  
  31.    if (nargs != 2) {
  32.        error("SINGSEN: Wrong number of input arguments.");
  33.    }
  34.  
  35. // Compute SVD of A
  36.    Adum=svd(A,"A");
  37.    U=Adum.u;
  38.    S=diag(Adum.sigma);
  39.    V=Adum.vt';
  40.  
  41. // Error Trap in SVD of A
  42.    Acheck=U*S*Adum.vt;
  43.    Aerr=norm(A-Acheck);
  44.    if (Aerr > 1.0e-12) {
  45.        error("SINGSEN: Error in taking svd of A");
  46.    }
  47.  
  48.    n=max(size(S));
  49.    svsen=zeros(n,1);
  50.  
  51.    for (i in 1:n) {
  52.        svsen[i]=real(U[;i]'*dAdp*V[;i]);
  53.    }
  54.  
  55.    return svsen
  56. };
  57.