Show
Ignore:
Timestamp:
02/27/08 22:37:35 (9 months ago)
Author:
otter
Message:

Math.Matrices.eigenValues/rank/singularValues lead to a crash, for matrices with zero dimensions.
This has been fixed

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/maintenance/2.2.2/Modelica/Math/package.mo

    r573 r1093  
    14191419      "Real-valued eigenvector matrix"; 
    14201420     
    1421     annotation (preferedView="info", 
    1422       Coordsys( 
    1423         extent=[-100, -100; 100, 100], 
    1424         grid=[2, 2], 
    1425         component=[20, 20]), 
    1426       Window( 
    1427         x=0.4, 
    1428         y=0.4, 
    1429         width=0.6, 
    1430         height=0.6), 
     1421    annotation ( 
    14311422      Documentation(info="<HTML> 
    14321423<h4>Syntax</h4> 
     
    14821473</HTML> 
    14831474")); 
     1475     
    14841476  protected  
    14851477    Integer info; 
     
    14871479    Boolean onlyEigenvalues = false; 
    14881480  algorithm  
     1481  if size(A,1) > 0 then 
    14891482    if onlyEigenvalues then 
    14901483       (eigenvalues[:, 1],eigenvalues[:, 2],info) := LAPACK.dgeev_eigenValues(A); 
     
    14961489\"Matrices.eigenvalues\" is not possible, since the 
    14971490numerical algorithm does not converge."); 
     1491  end if; 
    14981492  end eigenValues; 
    14991493   
     
    15721566    input Real A[:, :] "Matrix"; 
    15731567    output Real sigma[min(size(A, 1), size(A, 2))] "Singular values"; 
    1574     output Real U[size(A, 1), size(A, 1)]=zeros(size(A, 1), size(A, 1))  
     1568    output Real U[size(A, 1), size(A, 1)]=identity(size(A, 1))  
    15751569      "Left orthogonal matrix"; 
    1576     output Real VT[size(A, 2), size(A, 2)]=zeros(size(A, 2), size(A, 2))  
     1570    output Real VT[size(A, 2), size(A, 2)]=identity(size(A, 2))  
    15771571      "Transposed right orthogonal matrix "; 
    15781572     
    1579     annotation (preferedView="info", Documentation(info="<HTML> 
     1573    annotation ( Documentation(info="<HTML> 
    15801574<h4>Syntax</h4> 
    15811575<blockquote><pre> 
     
    16241618    Integer n=min(size(A, 1), size(A, 2)) "Number of singular values"; 
    16251619  algorithm  
    1626     (sigma,U,VT,info) := Matrices.LAPACK.dgesvd(A); 
     1620  if n>0 then 
     1621    (sigma,U,VT,info) := Modelica.Math.Matrices.LAPACK.dgesvd(A); 
    16271622    assert(info == 0, "The numerical algorithm to compute the 
    16281623singular value decomposition did not converge"); 
     1624  end if; 
    16291625  end singularValues; 
    16301626   
     
    16901686      "If eps > 0, the singular values are checked against eps; otherwise eps=max(size(A))*norm(A)*Modelica.Constants.eps is used"; 
    16911687    output Integer result "Rank of matrix A"; 
     1688     
     1689    annotation (Documentation(info="<html> 
     1690   
     1691</html>")); 
    16921692  protected  
    16931693    Integer n=min(size(A, 1), size(A, 2)); 
    16941694    Integer i=n; 
    1695     Real sigma[n]=singularValues(A) "Singular values"; 
    1696     Real eps2=if eps > 0 then eps else max(size(A))*sigma[1]*Modelica.Constants.eps; 
     1695    Real sigma[n]; 
     1696    Real eps2; 
    16971697  algorithm  
    1698     result := n; 
    1699     while i > 0 loop 
    1700       if sigma[i] > eps2 then 
    1701         result := i; 
    1702         i := 0; 
    1703       end if; 
    1704       i := i - 1; 
    1705     end while; 
    1706      
    1707     annotation (Documentation(info="<html> 
    1708    
    1709 </html>")); 
     1698    result := 0; 
     1699    if n > 0 then 
     1700      sigma := Modelica.Math.Matrices.singularValues(A); 
     1701      eps2 := if eps > 0 then eps else max(size(A))*sigma[1]*Modelica.Constants.eps; 
     1702      while i > 0 loop 
     1703        if sigma[i] > eps2 then 
     1704          result := i; 
     1705          i := 0; 
     1706        end if; 
     1707        i := i - 1; 
     1708      end while; 
     1709    end if; 
    17101710  end rank; 
    17111711