Example #1
0
 /// <summary>
 /// find some eigenvalues and -vectors of symmetric (hermitian) matrix
 /// </summary>
 /// <param name="A">input matrix, Size [n x n], symmetric (hermitian for complex A) </param> 
 /// <param name="V">output: n eigenvectors as columns. Size [n x n]. If V is null on input, the eigenvectors will not be computed and V is not changed. </param>
 /// <param name="rangeStart">The eigenvalues will be returned by increasing size. This will determine the number of the first eigenvalue to be returned.</param>
 /// <param name="rangeEnd">Determine the number of the last eigenvalue to be returned.</param>
 /// <returns>diagonal matrix of size [n,n] with eigenvalues of A on the main diagonal.</returns>
 /// <remarks><para>For computation the Lapack functions dsyevr, ssyevr, chesvr and zheesv are used. </para>
 /// <para>Since A is symmetric, the eigenvalues will always be real. Therefore the return value will be of the same inner type as A.</para></remarks>
 /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A is not square or <paramref name="rangeEnd"/> &lt; <paramref name="rangeStart"/> or if either one is &lt;= 0.</exception>
 public static /*!HC:HCCls1*/ ILArray<double> eigSymm (/*!HC:HCCls1*/ ILArray<double> A, ref /*!HC:HCCls1*/ ILArray<double> V, /*!HC:HCArrReal*/ double rangeStart, /*!HC:HCArrReal*/ double rangeEnd) {
     if (A.IsEmpty) {
         V = /*!HC:HCCls1*/ ILArray<double> .empty(A.Dimensions); 
         return /*!HC:HCCls1*/ ILArray<double> .empty(A.Dimensions); 
     }
     int n = A.Dimensions[0]; 
     if (n != A.Dimensions[1])
         throw new ILArgumentException("eigSymm: input matrix A must be square and symmetric/hermitian.");
     /*!HC:HCCls1*/ ILArray<double> ret = null; 
     int m = 0,ldz = 0,info = 0; 
     if (rangeStart > rangeEnd) 
         throw new ILArgumentException("eigSymm: invalid range of eigenvalues requested");
     /*!HC:HCCls1*/ ILArray<double> tmpA = A.copyUpperTriangle(n); 
     /*!HC:HCClsReal*/ ILArray<double> w = new /*!HC:HCClsReal*/ ILArray<double> (new /*!HC:HCArrReal*/ double [n],1,n); 
     /*!HC:HCArr1*/ double [] z; 
     char jobz;
     if (object.Equals(V,null)) {
         z = new /*!HC:HCArr1*/ double [1]; 
         jobz = 'N';             
         ldz = 1; 
     } else {
         z = new /*!HC:HCArr1*/ double [n * n];
         jobz = 'V';
         ldz = n; 
     } 
     int [] isuppz = new int[2 * n];
     /*!HC:lapack_???evr*/ Lapack.dsyevr (jobz,'V','U',n,tmpA.m_data,n,rangeStart,rangeEnd,0,0,0, ref m,w.m_data,z,ldz,isuppz,ref info);
     ret = ILMath.diag(/*!HC:HCClsConv3*/ /**/ (w)); 
     if (jobz == 'V') {
         V =  new  /*!HC:HCCls1*/ ILArray<double> (z,n,n);
         V = V[null,ILMath.vector(0,m-1)]; 
     }
Example #2
0
 /// <summary>
 /// find all eigenvalues of symmetric (hermitian) matrix
 /// </summary>
 /// <param name="A">input matrix, Size [n x n], symmetric (hermitian for complex A) </param> 
 /// <returns>array of size [n,1] with eigenvalues of A.</returns>
 /// <remarks><para>For computation the Lapack functions dsyevr, ssyevr, chesvr and zheesv are used. </para>
 /// <para>Since A is symmetric, the eigenvalues will always be real. Therefore the return value will be of the same inner type as A.</para></remarks>
 /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A is not square.</exception>
 public static /*!HC:HCCls1*/ ILArray<double> eigSymm (/*!HC:HCCls1*/ ILArray<double> A) {
     if (A.IsEmpty) {
         return /*!HC:HCCls1*/ ILArray<double> .empty(A.Dimensions); 
     }
     int n = A.Dimensions[0]; 
     if (n != A.Dimensions[1])
         throw new ILArgumentException("eigSymm: input matrix A must be square and symmetric/hermitian.");
     /*!HC:HCCls1*/ ILArray<double> ret = null; 
     int m = 0,info = 0; 
     /*!HC:HCCls1*/ ILArray<double> tmpA = A.copyUpperTriangle(n); 
     /*!HC:HCClsReal*/ ILArray<double> w = new /*!HC:HCClsReal*/ ILArray<double> (new /*!HC:HCArrReal*/ double [n],1,n); 
     /*!HC:HCArr1*/ double [] z = new /*!HC:HCArr1*/ double [1]; ; 
     int [] isuppz = new int[2 * n];
     /*!HC:lapack_???evr*/ Lapack.dsyevr ('N','A','U',n,tmpA.m_data,n,0,0,0,0,0,ref m,w.m_data,z,1,isuppz,ref info);
     ret = /*!HC:HCClsConv3*/ /**/ (w); 
     return ret; 
 }
 /// <summary>
 /// find all eigenvalues and -vectors of symmetric (hermitian) matrix
 /// </summary>
 /// <param name="A">input matrix, Size [n x n], symmetric (hermitian for complex A) </param> 
 /// <param name="V">output: n eigenvectors as columns. Size [n x n]. If V is null on input, the eigenvectors will not be computed and V is not changed. </param>
 /// <returns>diagonal matrix of size [n,n] with eigenvalues of A on the main diagonal.</returns>
 /// <remarks><para>For computation the Lapack functions dsyevr, ssyevr, chesvr and zheesv are used. </para>
 /// <para>Since A is symmetric, the eigenvalues will always be real. Therefore the return value will be of the same inner type as A.</para></remarks>
 /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A is not square.</exception>
 public static /*!HC:HCCls1*/ ILArray<double> eigSymm (/*!HC:HCCls1*/ ILArray<double> A, ref /*!HC:HCCls1*/ ILArray<double> V) {
     if (A.IsEmpty) {
         V = /*!HC:HCCls1*/ ILArray<double> .empty(A.Dimensions); 
         return /*!HC:HCCls1*/ ILArray<double> .empty(A.Dimensions); 
     }
     int n = A.Dimensions[0]; 
     if (n != A.Dimensions[1])
         throw new ILArgumentException("eigSymm: input matrix A must be square and symmetric/hermitian.");
     /*!HC:HCCls1*/ ILArray<double> ret = null; 
     int m = 0,ldz = 0,info = 0; 
     /*!HC:HCCls1*/ ILArray<double> tmpA = A.copyUpperTriangle(n); 
     /*!HC:HCClsReal*/ ILArray<double> w = new /*!HC:HCClsReal*/ ILArray<double> (new /*!HC:HCArrReal*/ double [n],n,1); 
     /*!HC:HCArr1*/ double [] z; 
     char jobz;
     if (object.Equals(V,null)) {
         z = new /*!HC:HCArr1*/ double [1]; 
         jobz = 'N';
         ldz = 1; 
     } else {
         z = new /*!HC:HCArr1*/ double [n * n];
         jobz = 'V';
         ldz = n; 
     } 
     int [] isuppz = new int[2 * n];
     /*!HC:lapack_???evr*/ Lapack.dsyevr (jobz,'A','U',n,tmpA.m_data,n,1,n,0,0,0,ref m,w.m_data,z,ldz,isuppz,ref info);
     if (info != 0) 
         throw new ILException("eigSymm: error returned from lapack: " + info); 
     if (jobz == 'V') {
         V =  new  /*!HC:HCCls1*/ ILArray<double> (z,n,n);
         V = V[null,ILMath.vector(0,m-1)]; 
         ret = ILMath.diag(/*!HC:HCClsConv3*/ /**/ (w)); 
     } else {
         ret = /*!HC:HCClsConv3*/ /**/ (w);
     }
     return ret; 
 }
 /// <summary>
 /// find some eigenvalues and -vectors of symmetric (hermitian) matrix
 /// </summary>
 /// <param name="A">input matrix, Size [n x n], symmetric (hermitian for complex A) </param> 
 /// <param name="V">output: n eigenvectors as columns. Size [n x n]. If V is null on input, the eigenvectors will not be computed and V is not changed. </param>
 /// <param name="rangeStart">specify the lowest limit for the range of eigenvalues to be queried.</param>
 /// <param name="rangeEnd">specify the upper limit for the range of eigenvalues to be queried.</param>
 /// <returns>diagonal matrix of size [n,n] with eigenvalues of A on the main diagonal.</returns>
 /// <remarks><para>For computation the Lapack functions dsyevr, ssyevr, chesvr and zheesv are used. </para>
 /// <para>Since A is symmetric, the eigenvalues will always be real. Therefore the return value will be of the same inner type as A.</para></remarks>
 /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if A is not square or <paramref name="rangeEnd"/> &lt; <paramref name="rangeStart"/></exception>
 public static /*!HC:HCCls1*/ ILArray<double> eigSymm (/*!HC:HCCls1*/ ILArray<double> A, ref /*!HC:HCCls1*/ ILArray<double> V, int rangeStart, int rangeEnd) {
     if (A.IsEmpty) {
         V = /*!HC:HCCls1*/ ILArray<double> .empty(A.Dimensions); 
         return /*!HC:HCCls1*/ ILArray<double> .empty(A.Dimensions); 
     }
     int n = A.Dimensions[0]; 
     if (n != A.Dimensions[1])
         throw new ILArgumentException("eigSymm: input matrix A must be square and symmetric/hermitian.");
     /*!HC:HCCls1*/ ILArray<double> ret = null; 
     int m = 0,ldz = 0,info = 0; 
     if (rangeEnd < rangeStart || rangeStart < 1) 
         throw new ILArgumentException("eigSymm: invalid range of eigenvalues requested");
     /*!HC:HCCls1*/ ILArray<double> tmpA = A.copyUpperTriangle(n); 
     /*!HC:HCClsReal*/ ILArray<double> w = new /*!HC:HCClsReal*/ ILArray<double> (new /*!HC:HCArrReal*/ double [n],1,n); 
     /*!HC:HCArr1*/ double [] z; 
     char jobz;
     if (object.Equals(V,null)) {
         z = new /*!HC:HCArr1*/ double [1]; 
         jobz = 'N';
         ldz = 1; 
     } else {
         z = new /*!HC:HCArr1*/ double [n * n];
         jobz = 'V';
         ldz = n; 
     } 
     int [] isuppz = new int[2 * n];
     /*!HC:lapack_???evr*/ Lapack.dsyevr (jobz,'I','U',n,tmpA.m_data,n,0,0,rangeStart,rangeEnd,0,ref m,w.m_data,z,ldz,isuppz,ref info);
     ret = ILMath.diag(/*!HC:HCClsConv3*/ /**/ (w)); 
     if (jobz == 'V') {
         V =  new  /*!HC:HCCls1*/ ILArray<double> (z,n,n);
         V = V[null,ILMath.vector(0,m-1)]; 
     }
     return ret; 
 }