/* nag_complex_svd (f02xec) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. * Mark 8 revised, 2004. */ #include #include #include #include #define COMPLEX(A) A.re, A.im #define COMPLEX_CONJ(A) A.re, -A.im static int ex1(void), ex2(void); int main(void) { Integer exit_status_ex1=0; Integer exit_status_ex2=0; Vprintf("nag_complex_svd (f02xec) Example Program Results\n"); Vscanf(" %*[^\n]"); /* Skip heading in data file */ exit_status_ex1 = ex1(); exit_status_ex2 = ex2(); return exit_status_ex1 == 0 && exit_status_ex2 == 0 ? 0 : 1; } #define A(I,J) a[(I)*tda + J] #define B(I,J) b[(I)*tdb + J] #define PH(I,J) ph[(I)*tdph + J] static int ex1(void) { Nag_Boolean wantp, wantq; Complex *a=0, *b=0, *dummy=0, *ph=0; Integer exit_status=0, failinfo, i, iter, j, m, n, ncolb, tda, tdb, tdph; NagError fail; double *e=0, *sv=0; INIT_FAIL(fail); Vprintf("Example 1\n\n"); Vscanf(" %*[^\n]"); /* Skip heading in data file */ if (scanf("%ld%ld", &m, &n) != EOF) { if (m>=0 && n>=0) { ncolb = 1; if ( !( e = NAG_ALLOC(MIN(m,n)-1, double)) || !( sv = NAG_ALLOC(MIN(m,n), double)) || !( a = NAG_ALLOC(m*n, Complex)) || !( b = NAG_ALLOC(m*ncolb, Complex)) || !( ph = NAG_ALLOC(n*n, Complex)) || !( dummy = NAG_ALLOC(1, Complex)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; tdb = ncolb; tdph = n; } else { Vprintf("Invalid m or n.\n"); exit_status = 1; return exit_status; } for (i=0; i=0 && n>=0) { if ( !( e = NAG_ALLOC(MIN(m,n)-1, double)) || !( sv = NAG_ALLOC(MIN(m,n), double)) || !( a = NAG_ALLOC(m*n, Complex)) || !( q = NAG_ALLOC(m*m, Complex)) || !( dummy = NAG_ALLOC(1, Complex)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; tdq = m; } else { Vprintf("Invalid m or n.\n"); exit_status = 1; return exit_status; } for (i=0; i