/*------------------------------------------------------------------------------* * File Name: OCN_f.h * * Creation: TCZ 7/20/2001 * * Purpose: Origin C Header for NAG functions * * Copyright (c) OriginLab Corp. 2001 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #ifndef _O_NAG_f_H #define _O_NAG_f_H #importdll "ONAG" // NAG DLL prepared by OriginLab #include /* begin proto */ /** f01bnc computes a Cholesky factorization of a complex positive-definite Hermitian matrix. Example: This example computes the Cholesky factorization of the well-conditioned positive-definite Hermitian matrix . .. 15 1 - 2i 2 -4 + 3i 1 + 2i 20 -2 + i 3 - 3i 2 -2 - i 18 -1 + 2i -4 - 3i 3 + 3i -1 - 2i 26 . .. . void test_nag_complex_cholesky() { int i, j, n; matrix a; a.SetSize(8,8); double p[8]; printf("f01bnc Example Program Results\n"); a[0][0] = 15.0+0.0i; a[1][0] = 1.0+2.0i; a[1][1] = 20.0+0.0i; a[2][0] = 2.0+0.0i; a[2][1] = -2.0-1.0i; a[2][2] = 18.0+0.0i; a[3][0] = -4.0-3.0i; a[3][1] = 3.0+3.0i; a[3][2] = -1.0-2.0i; a[3][3] = 26.0+0.0i; n = 4; nag_complex_cholesky(n,a,8,p); complex gh; printf("\n Upper triangle of Complex matrix U by rows\n"); for (i=0; i theta; theta.SetSize(1,10); //{0.0-0.3i,0.3+0.3i,0.0+2.4i}}; matrix a; a.SetSize(20,10); a[0][0] = 0.0+0.5i; a[0][1] = -0.5+1.5i; a[0][2] = -1.0+1.0i; a[1][0] = 0.4+0.3i; a[1][1] = 0.9+1.3i; a[1][2] = 0.2+1.4i; a[2][0] = 0.4+0.0i; a[2][1] = -0.4+0.4i; a[2][2] = 1.8+0.0i; a[3][0] = 0.3-0.4i; a[3][1] = 0.1+0.7i; a[3][2] = 0.0+0.0i; a[4][0] = 0.0-0.3i; a[4][1] = 0.3+0.3i; a[4][2] = 0.0+2.4i; m = 5; n = 3; printf("A=\n"); for (i=0; i a, b, theta; a.SetSize(20,10); b.SetSize(20,5); theta.SetSize(1,10); m = 5; n = 3; a[0][0] = 0.0+0.5i; a[0][1] = -0.5+1.5i; a[0][2] = -1.0+1.0i; a[1][0] = 0.4+0.3i; a[1][1] = 0.9+1.3i; a[1][2] = 0.2+1.4i; a[2][0] = 0.4+0.0i; a[2][1] = -0.4+0.4i; a[2][2] = 1.8+0.0i; a[3][0] = 0.3-0.4i; a[3][1] = 0.1+0.7i; a[3][2] = 0.0+0.0i; a[4][0] = 0.0-0.3i; a[4][1] = 0.3+0.3i; a[4][2] = 0.0+2.4i; ncolb = 2; b[0][0] =-0.55 +1.05i; b[0][1] =0.45+1.05i; b[1][0] = 0.49 + 0.93i; b[1][1] = 1.09+0.13i; b[2][0] =0.56 - 0.16i; b[2][1] = 0.64+0.16i; b[3][0] =0.39+0.23i; b[3][1] = -0.39-0.23i; b[4][0] =1.13+0.83i; b[4][1] = -1.13+0.77i; nag_complex_qr(m,n, a, 10, theta); nag_complex_apply_q(ConjugateTranspose, Nag_ElementsSeparate, m,n,a, 10, theta, ncolb, b, 5); printf("\nMatrix conjg( Q' )*B\n"); for (i=0; ia, q, theta; a.SetSize(20,10); q.SetSize(20,20); theta.SetSize(1,10); m = 5; n = 3; a[0][0] = 0.0+0.5i; a[0][1] = -0.5+1.5i; a[0][2] = -1.0+1.0i; a[1][0] = 0.4+0.3i; a[1][1] = 0.9+1.3i; a[1][2] = 0.2+1.4i; a[2][0] = 0.4+0.0i; a[2][1] = -0.4+0.4i; a[2][2] = 1.8+0.0i; a[3][0] = 0.3-0.4i; a[3][1] = 0.1+0.7i; a[3][2] = 0.0+0.0i; a[4][0] = 0.0-0.3i; a[4][1] = 0.3+0.3i; a[4][2] = 0.0+2.4i; nag_complex_qr(m, n, a, 10, theta); for (j=0; j r; r.SetSize(1,4); int iter[4]; n = 4; a[0][0] = 1.5; a[0][1] = 0.1; a[0][2] = 4.5; a[0][3] = -1.5; a[1][0] = -22.5; a[1][1] = 3.5; a[1][2] = 12.5; a[1][3] = -2.5; a[2][0] = -2.5; a[2][1] = 0.3; a[2][2] = 4.5; a[2][3] = -2.5; a[3][0] = -2.5; a[3][1] = 0.1; a[3][2] = 4.5; a[3][3] = 2.5; nag_real_eigenvalues(n, a, 4, r, iter); printf("Eigenvalues\n"); for (i=0; ir, v; r.SetSize(1,4); v.SetSize(4,4); int iter[4]; a[0][0] = 1.5; a[0][1] = 0.1; a[0][2] = 4.5; a[0][3] = -1.5; a[1][0] = -22.5; a[1][1] = 3.5; a[1][2] = 12.5; a[1][3] = -2.5; a[2][0] = -2.5; a[2][1] = 0.3; a[2][2] = 4.5; a[2][3] = -2.5; a[3][0] = -2.5; a[3][1] = 0.1; a[3][2] = 4.5; a[3][3] = 2.5; n = 4; nag_real_eigensystem(n, a, 4, r, v, 4, iter); printf("Eigenvalues\n"); for (i=0; ia; a.SetSize(4,4); double r[4]; n = 4; a[0][0] = 0.50 + 0.00i; a[0][1] = 0.00 + 0.00i; a[0][2] = 1.84 + 1.38i; a[0][3] = 2.08 - 1.56i; a[1][0] = 0.00 + 0.00i; a[1][1] = 0.50 + 0.00i; a[1][2] = 1.12 + 0.84i; a[1][3] = -0.56 + 0.42i; a[2][0] = 1.84 - 1.38i; a[2][1] = 1.12 - 0.84i; a[2][2] = 0.50 + 0.00i; a[2][3] = 0.00 + 0.00i; a[3][0] = 2.08 + 1.56i; a[3][1] = -0.56 - 0.42i; a[3][2] = 0.00 + 0.00i; a[3][3] = 0.50 + 0.00i; nag_hermitian_eigenvalues(n, a, 4, r); printf("Eigenvalues\n"); for (i=0; i a, v; a.SetSize(4,4); v.SetSize(4,4); double r[4]; n = 4; a[0][0] = 0.50 + 0.00i; a[0][1] = 0.00 + 0.00i; a[0][2] = 1.84 + 1.38i; a[0][3] = 2.08 - 1.56i; a[1][0] = 0.00 + 0.00i; a[1][1] = 0.50 + 0.00i; a[1][2] = 1.12 + 0.84i; a[1][3] = -0.56 + 0.42i; a[2][0] = 1.84 - 1.38i; a[2][1] = 1.12 - 0.84i; a[2][2] = 0.50 + 0.00i; a[2][3] = 0.00 + 0.00i; a[3][0] = 2.08 + 1.56i; a[3][1] = -0.56 - 0.42i; a[3][2] = 0.00 + 0.00i; a[3][3] = 0.50 + 0.00i; nag_hermitian_eigensystem(n, a, 4, r, v, 4); printf("Eigenvalues\n"); for (i=0; i alfa; alfa.SetSize(1,8); double beta[8], eps1; matrix a, b, z; a.SetSize(8,8); b.SetSize(8,8); z.SetSize(8,8); BOOL matz; n = 4; a[0][0] = 3.9; a[0][1] = 12.5; a[0][2] = -34.5; a[0][3] = -0.5; a[1][0] = 4.3; a[1][1] = 21.5; a[1][2] = -47.5; a[1][3] = 7.5; a[2][0] = 4.3; a[2][1] = 21.5; a[2][2] = -43.5; a[2][3] = 3.5; a[3][0] = 4.4; a[3][1] = 26.0; a[3][2] = -46.0; a[3][3] = 6.0; b[0][0] = 1.0; b[0][1] = 2.0; b[0][2] = -3.0; b[0][3] = 1.0; b[1][0] = 1.0; b[1][1] = 3.0; b[1][2] = -5.0; b[1][3] = 4.0; b[2][0] = 1.0; b[2][1] = 3.0; b[2][2] = -4.0; b[2][3] = 3.0; b[3][0] = 1.0; b[3][1] = 3.0; b[3][2] = -4.0; b[3][3] = 4.0; matz = TRUE; eps1 = 1e-8; nag_real_general_eigensystem(n, a, 8, b, 8, eps1, alfa, beta, matz, z, 8, iter); ip = 0; for (i=0; i 0.0, an element will be considered negligible if it is less than tol times the norm of its matrix. If tol = 0.0, machine precision is used in place of tol. A value of tol greater than machine precision may result in faster execution but less accurate results. complex alfa[], // Output: alpha_j, for j = 1, 2, . . . , n. double beta[], // Output: beta_j, for j = 1, 2, . . . , n. bool wantv, // wantv must be set to TRUE if the eigenvectors are required. If wantv is set to FALSE then the array v is not referenced. double v[], // Output: if wantv = TRUE, then (i) if the jth eigenvalue is real, the jth column of v contains its eigenvector; (ii) if the jth and (j + 1)th eigenvalues form a complex pair, the jth and (j + 1)th columns of v contain the real and imaginary parts of the eigenvector associated with the first eigenvalue of the pair. The conjugate of this vector is the eigenvector for the conjugate eigenvalue. Each eigenvector is normalised so that the component of largest modulus is real and the sum of squares of the moduli equal one. If wantv = FALSE, v is not referenced and may be set to the null pointer int tdv, // the second dimension of the array v as declared in the function from which nag real general eigensystem is called. int iter[] // contains the number of iterations needed to obtain the jth eigenvalue. ); /** f02ecc computes selected eigenvalues and eigenvectors of a real general matrix. Example: To compute those eigenvalues of the matrix A whose moduli lie in the range [0.2,0.5], and their corresponding eigenvectors, where A = . .. 0.35 0.45 -0.14 -0.17 0.09 0.07 -0.54 0.35 -0.44 -0.33 -0.03 0.17 0.25 -0.32 -0.13 0.11 . void test_nag_real_eigensystem_sel() { matrix a; a.SetSize(8,8); double wl, wu; int i, j, m, n; int mest = 3; matrixw, v; w.SetSize(1,8); v.SetSize(8,3); n = 4; wl = 0.2; wu = 0.5; a[0][0] =0.35; a[0][1] =0.45; a[0][2] =-0.14; a[0][3] = -0.17; a[1][0] =0.09; a[1][1] =0.07; a[1][2] = -0.54; a[1][3] =0.35; a[2][0] =-0.44; a[2][1] =-0.33; a[2][2] =-0.03; a[2][3] =0.17; a[3][0] =0.25; a[3][1] =-0.32; a[3][2] =-0.13; a[3][3] =0.11; nag_real_eigensystem_sel(Nag_Select_Modulus, n, a, 8, wl, wu, mest, &m, w,v, 3); printf("\n\nEigenvalues\n"); for (i = 0; i < m; ++i) { complex temp; temp = w[0][i]; printf("(%7.4f, %7.4f) ", temp.m_re, temp.m_im); } printf("\n"); printf(" Eigenvectors\n "); for (i = 1; i <= m; i++) { printf("%15ld", i); if(i%m == 0 ) printf("\n"); } for (i = 0; i < n; i++) { printf("%ld ", i + 1); for (j = 0; j < m; j++) { complex temp; temp = v[i][j]; printf("(%8.4f, %8.4f)", temp.m_re, temp.m_im); if((j + 1) % m == 0) printf("\n"); } } } The output is following: Eigenvalues (-0.0994, 0.4008) (-0.0994, -0.4008) Eigenvectors 1 2 1 ( -0.1933, 0.2546) ( -0.1933, -0.2546) 2 ( 0.2519, -0.5224) ( 0.2519, 0.5224) 3 ( 0.0972, -0.3084) ( 0.0972, 0.3084) 4 ( 0.6760, 0.0000) ( 0.6760, 0.0000) Parameters: Return: This function returns NAG error code, 0 if no error. 70: On entry, parameter crit had an illegal value. 11: On entry, n must not be less than 0: n = _value_. On entry, mest must not be less than 1: mest = _value_. 91: On entry, tda = _value_ while n = _value_. Constraint: tda = max(1,n). On entry, tdv = _value_ while mest = _value_. Constraint: tdv = max(1,mest). 24: On entry, wu = _value_ while wl = _value_. These parameters must satisfy wu > wl. 378: The QR algorithm failed to compute all the eigenvalues. No eigenvectors have been computed. 379: There are more than mest eigenvalues in the speci.ed range. The actual number of eigenvalues in the range is returned in m. No eigenvectors have been computed. Rerun with the second dimension of v = mest = m. successfully call of the nag_real_eigensystem_sel function. */ int nag_real_eigensystem_sel( Nag_Select_Eigenvalues crit, int n, // the order of the matrix A. double a[], // Input: the n by n general matrix A. Output: a contains the Hessenberg form of the balanced input matrix A_ int tda, // the last dimension of the array a as declared in the calling program. double wl, // the lower bound on the criterion for the selected eigenvalues. double wu, // the upper bound on the criterion for the selected eigenvalues. int mest, // an upper bound on m, the number of eigenvalues and eigenvectors selected. No eigenvectors are computed if mest < m. int *m, // the number of eigenvalues actually selected complex w[], // the first m elements of w hold the values of the selected eigenvalues; elements from the index m to n-1 contain the other eigenvalues. Complex conjugate pairs of eigenvalues are stored in consecutive elements of the array, with the eigenvalue having the positive imaginary part first. complex v[], // the selected eigenvectors, with the ith column holding the eigenvector associated with the eigenvalue lamda. int tdv // the second dimension of the array v as declared in the calling program. ); /** f02gcc computes selected eigenvalues and eigenvectors of a complex general matrix. Example: To compute those eigenvalues of the matrix A whose moduli lie in the range [-5.5,+5.5], and their corresponding eigenvectors, where A = . .. -3.97 - 5.04i -4.11 + 3.70i -0.34 + 1.01i 1.29 - 0.86i 0.34 - 1.50i 1.52 - 0.43i 1.88 - 5.38i 3.36 + 0.65i 3.31 - 3.85i 2.50 + 3.45i 0.88 - 1.08i 0.64 - 1.48i -1.10 + 0.82i 1.81 - 1.59i 3.25 + 1.33i 1.57 - 3.44i . .. void test_nag_complex_eigensystem_sel() { double wl,wu; int mest = 3; int i,j,m, n; matrix a, v, w; a.SetSize(8,8); v.SetSize(8,3); w.SetSize(1,8); n = 4; wl = -5.5; wu = 5.5; a[0][0] = -3.97 - 5.04i; a[0][1] = -4.11 + 3.70i; a[0][2] = -0.34 + 1.01i; a[0][3] = 1.29 - 0.86i; a[1][0] = 0.34 - 1.50i; a[1][1] = 1.52 - 0.43i; a[1][2] = 1.88 - 5.38i; a[1][3] = 3.36 + 0.65i; a[2][0] = 3.31 - 3.85i; a[2][1] = 2.50 + 3.45i; a[2][2] = 0.88 - 1.08i; a[2][3] = 0.64 - 1.48i; a[3][0] = -1.10 + 0.82i; a[3][1] = 1.81 - 1.59i; a[3][2] = 3.25 + 1.33i; a[3][3] = 1.57 - 3.44i; nag_complex_eigensystem_sel(Nag_Select_Modulus, n, a, 8, wl, wu, mest, &m, w, v,3); printf("\n\nEigenvalues\n\n"); for (i = 0; i < m; ++i) { complex temp = w[0][i]; printf("(%7.4f,%7.4f)\t", temp.m_re, temp.m_im); if((i+1)%2 == 0) printf("\n"); } printf("\nEigenvectors\n"); for (i=1; i<=m; i++) { printf("%15ld",i); if(i%m == 0) printf("\n"); } for (i = 0; i < n; i++) { printf("% ld ",i + 1); for (j = 0; j < m; j++) { complex temp = v[i][j]; printf("(%8.4f,%8.4f)", temp.m_re, temp.m_im); if((j + 1)%m == 0) printf("\n"); } } } The output is following: Eigenvalues (-5.0000,2.0060) ( 3.0023, -3.9998) Eigenvectors 1 2 1 ( -0.3865, 0.1732) ( -0.0356, -0.1782) 2 ( -0.3539, 0.4529) ( 0.1264, 0.2666) 3 ( 0.6124, 0.0000) ( 0.0129, -0.2966) 4 ( -0.0859,-0.3284) ( 0.8898, 0.0000) Parameters: Return: This function returns NAG error code, 0 if no error. 70: On entry, parameter crit had an illegal value. 11: On entry, n must not be less than 0: n = _value_. On entry, mest must not be less than 1: mest = _value_. 91: On entry, tda = _value_ while n = _value_. Constraint: tda = max (1,n). 24: On entry, wu = _value_ while wl = _value_. These parameters must satisfy wu > wl. 17: On entry, tdv = _value_ while mest = _value_. These parameters must satisfy tdv = mest. 378: The QR algorithm failed to compute all the eigenvalues. No eigenvectors have been computed. 379: There are more than mest eigenvalues in the speci.ed range. The actual number of eigenvalues in the range is returned in m. No eigenvectors have been computed. Rerun with the second dimension of v = mest = m. 380: Inverse iteration failed to compute all the specified eigenvectors. If an eigenvector failed to converge, the corresponding column of v is set to zero. successfully call of the nag_complex_eigensystem_sel function. */ int nag_complex_eigensystem_sel( Nag_Select_Eigenvalues crit, int n, // the order of the matrix A. complex a[], // Input: the n by n general matrix A. Output: a contains the Hessenberg form of the balanced input matrix A int tda, // the last dimension of the array a as declared in the calling program. double wl, // the lower bound on the criterion for the selected eigenvalues. double wu, // the upper bound on the criterion for the selected eigenvalues. int mest, // an upper bound on m, the number of eigenvalues and eigenvectors selected. No eigenvectors are computed if mest < m. int *m, // the number of eigenvalues actually selected. complex w[], // the first m elements of w hold the selected eigenvalues; elements from the index m to n-1 contain the other eigenvalues. complex v[], // the selected eigenvectors, with the ith column holding the eigenvector associated with the eigenvalue lamda. int tdv // the second dimension of the array v as declared in the calling program. ); /** f02wec returns all, or part, of the singular value decomposition of a general real matrix. Example: To find the singular value decomposition of the 5 by 3 matrix A = . .... 2.0 2.5 2.5 2.0 2.5 2.5 1.6 -0.4 2.8 2.0 -0.5 0.5 1.2 -0.3 -2.9 . .... together with the vector QT b for the vector b = . .... 1.1 0.9 0.6 0.0 -0.8 . .... . void test_nag_real_svd() { int tda = 10; int tdpt = 10; matrix a; double b[20],e[9]; a.SetSize(20,10); matrix pt; pt.SetSize(10,10); double sv[10], dummy[1]; int i, j, m, n, iter, failinfo; BOOL wantp, wantq; m = 5; n = 3; a[0][0] = 2.0; a[0][1] = 2.5; a[0][2] = 2.5; a[1][0] = 2.0; a[1][1] = 2.5; a[1][2] = 2.5; a[2][0] = 1.6; a[2][1] = -0.4; a[2][2] = 2.8; a[3][0] = 2.0; a[3][1] = -0.5; a[3][2] = 0.5; a[4][0] = 1.2; a[4][1] = -0.3; a[4][2] = -2.9; b[0] = 1.1; b[1] = 0.9; b[2] = 0.6; b[3] = 0.0; b[4] = -0.8; wantq = TRUE; wantp = TRUE; nag_real_svd(m, n, a, tda, 1, b, 1, wantq, dummy, 1, sv, wantp, pt, tdpt, &iter, e, &failinfo); printf("Singular value decomposition of A\n\n"); printf("Singular values\n"); for (i = 0; i < n; ++i) printf(" %8.4f", sv[i]); printf("\n\n"); printf("Left-hand singular vectors, by column\n"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) printf(" %8.4f", a[i][j]); printf("\n"); } printf("\n"); printf("Right-hand singular vectors, by column\n"); for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) printf(" %8.4f", pt[j][i]); printf("\n"); } printf("\n"); printf("Vector Q'*B\n"); for (i = 0; i < m; ++i) printf(" %8.4f", b[i]); printf("\n\n"); } The output is following: Example 2 Singular value decomposition of A Singular values 6.5616 3.0000 2.4384 Left-hand singular vectors, by column 0.6011 -0.1961 -0.3165 0.6011 -0.1961 -0.3165 0.4166 0.1569 0.6941 0.1688 -0.3922 0.5636 -0.2742 -0.8629 0.0139 Right-hand singular vectors, by column 0.4694 -0.7845 0.4054 0.4324 -0.1961 -0.8801 0.7699 0.5883 0.2471 Vector Q'*B 1.6716 0.3922 -0.2276 -0.1000 -0.1000 Parameters: Return: This function returns NAG error code, 0 if no error. 11: On entry, m must not be less than 0: m = _value_. On entry, n must not be less than 0: n = _value_. On entry, ncolb must not be less than 0: ncolb = _value_. 17: On entry, tda = _value_ while n = _value_. These parameters must satisfy tda = n. On entry, tdb = _value_ while ncolb = _value_. These parameters must satisfy tdb = ncolb. 363: On entry, tdq = _value_ while m = _value_. Whenwantq is TRUE and m < n then relationship tdq = m must be satis.ed. 364: On entry, tdpt = _value_ while n = _value_. When wantq and wantp are TRUE and m = n then relationship tdpt = n must be satis.ed. 366: The QR algorithm has failed to converge in _value_ iterations. Singular values 1,2,. . .,failinfo may not have been found correctly and the remaining singular values may not be the smallest. The matrix A will nevertheless have been factorized as A = QEPT , where the leading min(m, n) by min(m, n) part of E is a bidiagonal matrix with sv[0], sv[1], . . ., sv[min(m,n-1)] as the diagonal elements and e[0], e[1], . . ., e[min(m,n-2)] as the superdiagonal elements. This failure is not likely to occur. 73: Memory allocation failed. successfully call of the nag_real_svd function. */ int nag_real_svd( int m, // the number of rows, m, of the matrix A. int n, // the number of columns, n, of the matrix A. double a[], // Input: the leading m by n part of the array a must contain the matrix A whose singular value decomposition is required. Output: if m = n and wantq = TRUE, then the leading m by n part of a will contain the first n columns of the orthogonal matrix Q. If m < n and wantp = TRUE, then the leading m by n part of a will contain the .rst m rows of the orthogonal matrix PT . If m = n and wantq = FALSE and wantp = TRUE, then the leading n by n part of a will contain the first n rows of the orthogonal matrix PT . Otherwise the contents of the leading m by n part of a are indeterminate. int tda, // the second dimension of the array a as declared in the function from which nag real svd is called. int ncolb, // the number of columns of the matrix B. When ncolb = 0 the array b is not referenced. double b[], // Input: if ncolb > 0, the leading m by ncolb part of the array b must contain the matrix to be transformed. If ncolb = 0 the array b is not referenced and may be set to the null pointer, i.e., (double *)0. Output: b is overwritten by the m by ncolb matrix QTB. int tdb, // the second dimension of the array b as declared in the function from which nag real svd is called. bool wantq, // wantq must be TRUE, if the left-hand singular vectors are required. If wantq = FALSE, then the array q is not referenced. double q[], // if m < n and wantq = TRUE, the leading m by m part of the array q will contain the orthogonal matrix Q. Otherwise the array q is not referenced and may be set to the null pointer, i.e., (double *)0. int tdq, // the second dimension of the array q as declared in the function from which nag real svd is called. double sv[], // the min(m,n) diagonal elements of the matrix S. bool wantp, // wantp must be TRUE if the right-hand singular vectors are required. If wantp = FALSE, then the array pt is not referenced. double pt[], // if m = n and wantq and wantp are TRUE, the leading n by n part of the array pt will contain the orthogonal matrix PT . Otherwise the array pt is not referenced and may be set to the null pointer, i.e., (double *)0. int tdpt, // the second dimension of the array pt as declared in the function from which nag real svd is called. int *iter, // the total number of iterations taken by the QR algorithm. double e[], // if the error NE QR NOT CONV occurs the array e contains the super diagonal elements of matrix E in the factorisation of A according to A = QEPT . See Section 5 for further details. int *failinfo // if the error NE QR NOT CONV occurs failinfo contains the number of singular values which may not have been found correctly. See Section 5 for details. ); /** f02xec returns all, or part, of the singular value decomposition of a general complex matrix. Example: To find the singular value decomposition of the 5 by 3 matrix A = . .... 0.5i -0.5 + 1.5i -1.0+ 1.0i 0.4 + 0.3i 0.9 + 1.3i 0.2+ 1.4i 0.4 -0.4 + 0.4i 1.8 0.3 - 0.4i 0.1 + 0.7i 0.0 -0.3i 0.3 + 0.3i 2.4i . .... together with the vector QHb for the vector b = . .... -0.55 + 1.05i 0.49 + 0.93i 0.56 - 0.16i 0.39 + 0.23i 1.13 + 0.83i . .... . void test_nag_complex_svd() { int tda = 10; int tdph = 10; matrixa, b, ph, dummy; a.SetSize(20,10); b.SetSize(1,20); ph.SetSize(10,10); dummy.SetSize(1,1); double e[9], sv[10]; int i, j, m, n, iter, failinfo; BOOL wantp, wantq; m = 5; n = 3; a[0][0] =0.00 + 0.50i; a[0][1] = -0.50 + 1.50i; a[0][2] = -1.00 + 1.00i; a[1][0] =0.40 + 0.30i; a[1][1] = 0.90 + 1.30i; a[1][2] = 0.20 + 1.40i; a[2][0] =0.40 + 0.00i; a[2][1] = -0.40 + 0.40i; a[2][2] = 1.80 + 0.00i; a[3][0] =0.30 - 0.40i; a[3][1] = 0.10 + 0.70i; a[3][2] = 0.00 + 0.00i; a[4][0] = 0.00 - 0.30i; a[4][1] = 0.30 + 0.30i; a[4][2] = 0.00 + 2.40i; b[0][0] = -0.55 + 1.05i; b[0][1] = 0.49 + 0.93i; b[0][2] = 0.56 - 0.16i; b[0][3] = 0.39 + 0.23i; b[0][4] = 1.13 + 0.83i; wantq = TRUE; wantp = TRUE; nag_complex_svd(m, n, a, tda, 1, b, 1, wantq, dummy, 1, sv, wantp, ph, tdph, &iter, e, &failinfo); printf("Singular value decomposition of A\n\nSingular values\n"); for (i=0; i 0, the leading m by ncolb part of the array b must contain the matrix to be transformed. If ncolb = 0 the array b is not referenced and may be set to the null pointer, i.e., (Complex *)0. Output: b is overwritten by the m by ncolb matrix QHB. int tdb, // the second dimension of the array b as declared in the function from which nag complex svd is called. bool wantq, // Input: wantq must be TRUE if the left-hand singular vectors are required. If wantq = FALSE then the array q is not referenced. complex q[], // Output: if m < n and wantq = TRUE, the leading m by m part of the array q will contain the unitary matrix Q. Otherwise the array q is not referenced and may be set to the null pointer, i.e., (Complex *)0. int tdq, // the second dimension of the array q as declared in the function from which nag complex svd is called. double sv[], // the min(m,n) diagonal elements of the matrix S. bool wantp, // wantp must be TRUE if the right-hand singular vectors are required. If wantp = FALSE then the array ph is not referenced complex ph[], // if m = n and wantq and wantp are TRUE, the leading n by n part of the array ph will contain the unitary matrix PH. Otherwise the array ph is not referenced and may be set to the null pointer, i.e., (Complex *)0. int tdph, // the second dimension of the array ph as declared in the function from which nag complex svd is called. int *iter, // the total number of iterations taken by the QR algorithm. double e[], // if the error NE QR NOT CONV occurs the array e contains the super-diagonal elements of matrix E in the factorisation of A according to A = QEPH. See Section 5 for further details. int *failinfo // if the error NE QR NOT CONV occurs failinfo contains the number of singular values which may not have been found correctly. See Section 5 for details. ); /** f03aec */ int nag_real_cholesky( int n, double a[], int tda, double p[], double *detf, int *dete ); /** f03afc */ int nag_real_lu( int n, double a[], int tda, int pivot[], double *detf, int *dete ); /** f03ahc */ int nag_complex_lu( int n, complex a[], int tda, int pivot[], complex *detf, int *dete ); /** f04adc */ int nag_complex_lin_eqn_mult_rhs( int n, int nrhs, complex a[], int tda, complex b[], int tdb, complex x[], int tdx ); /** f04agc */ int nag_real_cholesky_solve_mult_rhs( int n, int nrhs, double a[], int tda, double p[], double b[], int tdb, double x[], int tdx ); /** f04ajc */ int nag_real_lu_solve_mult_rhs( int n, int nrhs, double a[], int tda, int pivot[], double b[], int tdb ); /** f04akc */ int nag_complex_lu_solve_mult_rhs( int n, int nrhs, complex a[], int tda, int pivot[], complex b[], int tdb ); /** f04arc */ int nag_real_lin_eqn( int n, double a[], int tda, double b[], double x[] ); /** f04awc */ int nag_hermitian_lin_eqn_mult_rhs( int n, int nrhs, complex a[], int tda, double p[], complex b[], int tdb, complex x[], int tdx ); /** f04mcc */ int nag_real_cholesky_skyline_solve( Nag_SolveSystem selct, int n, int nrhs, double al[], int lal, double d[], int row[], double b[], int tdb, double x[], int tdx ); /** f03aec computes a Cholesky factorization of a real symmetric positive-definite matrix, and evaluates the determinant. Example: To compute a Cholesky factorization and calculate the determinant of the real symmetric positive-definite matrix . .. 6 7 6 5 7 11 8 7 6 8 11 9 5 7 9 11 . .. . void test_nag_real_cholesky() { double detf, determ; matrix a; a.SetSize(8,8); double p[8]; int i, dete, j, n; n = 4; a[0][0] = 6; a[0][1] = 7; a[0][2] = 6; a[0][3] = 5; a[1][0] = 7; a[1][1] = 11; a[1][2] = 8; a[1][3] = 7; a[2][0] = 6; a[2][1] = 8; a[2][2] = 11; a[2][3] = 9; a[3][0] = 5; a[3][1] = 7; a[3][2] = 9; a[3][3] = 11; nag_real_cholesky(n, a, 8, p, &detf, &dete); printf("Array A after factorization\n"); for (i=0; i a; a.SetSize(5,5); complex det; int i, j, n, dete; n = 3; a[0][0] = 2.0 + 0.0i; a[0][1] = 1.0 + 2.0i; a[0][2] = 2.0 + 10.0i; a[1][0] = 1.0 + 1.0i; a[1][1] = 1.0 + 3.0i; a[1][2] = -5.0 +14.0i; a[2][0] = 1.0 + 1.0i; a[2][1] = 0.0 + 5.0i; a[2][2] = -7.0 + 20.0i; nag_complex_lu(n, a, 5, pivot, &det, &dete); printf("Array a after factorization\n"); for (i=0; i a, b, x; a.SetSize(5,5); b.SetSize(5,1); x.SetSize(5,1); int i, j, n, l = 1; n = 3; a[0][0] = 1.0 + 0.0i; a[0][1] = 1.0 + 2.0i; a[0][2] = 2.0 +10.0i; a[1][0] = 1.0 + 1.0i; a[1][1] = 0.0 + 3.0i; a[1][2] = -5.0 +14.0i; a[2][0] = 1.0 + 1.0i; a[2][1] = 0.0 + 5.0i; a[2][2] = -8.0 + 20.0i; b[0][0] = 1.0 + 0.0i; b[1][0] = 0.0 + 0.0i; b[2][0] = 0.0 + 0.0i; nag_complex_lin_eqn_mult_rhs(n, 1, a, 5, b, 1, x, 1); printf("Solution\n"); for (i=0; ia, b; a.SetSize(NMAX,TDA); b.SetSize(NMAX,TDB); int i, j, n, dete, nrhs = 1; int pivot[5]; n = 3; a[0][0] = 1.0 + 0.0i; a[0][1] = 1.0 + 2.0i; a[0][2] = 2.0 +10.0i; a[1][0] = 1.0 + 1.0i; a[1][1] = 0.0 + 3.0i; a[1][2] = -5.0 + 14.0i; a[2][0] = 1.0 + 1.0i; a[2][1] = 0.0 + 5.0i; a[2][2] = -8.0 + 20.0i; b[0][0] = 1.0 + 0.0i; b[1][0] = 0.0 + 0.0i; b[2][0] = 0.0 + 0.0i; nag_complex_lu(n, a, TDA, pivot, &det, &dete); nag_complex_lu_solve_mult_rhs(n, nrhs, a, TDA, pivot, b, TDB); printf("Solution\n"); for (i=0; i a, b, x; a.SetSize(NMAX,TDA); b.SetSize(NMAX,TDB); x.SetSize(NMAX,TDX); double p[8]; int nrhs = 1; n = 4; a[0][0] = 15.0 + 0.0i; a[1][0] = 1.0 + 2.0i; a[1][1] = 20.0 + 0.0i; a[2][0] = 2.0 + 0.0i; a[2][1] = -2.0 -1.0i; a[2][2] = 18.0 + 0.0i; a[3][0] = -4.0 - 3.0i; a[3][1] = 3.0 + 3.0i; a[3][2] = -1.0 - 2.0i; a[3][3] = 26.0 + 0.0i; b[0][0] = 25.0 + 34.0i; b[1][0] = 21.0 + 19.0i; b[2][0] = 12.0 - 21.0i; b[3][0] = 21.0 - 27.0i; nag_complex_cholesky(n, a, TDA, p); nag_hermitian_lin_eqn_mult_rhs(n, nrhs, a, TDA, p, b, TDB, x, TDX); printf("\nSolution\n\n"); for (i=0; i