NAG Library Function Document nag_real_sym_posdef_tridiag_lin_solve (f04bgc)

Similar documents
NAG Library Function Document nag_herm_posdef_tridiag_lin_solve (f04cgc)

NAG Library Function Document nag_complex_tridiag_lin_solve (f04ccc)

NAG Library Function Document nag_complex_gen_lin_solve (f04cac)

NAG Library Function Document nag_dgglse (f08zac)

NAG Library Function Document nag_dgttrs (f07cec)

NAG Library Function Document nag_dgetri (f07ajc)

NAG Library Function Document nag_dtrsyl (f08qhc)

NAG Library Function Document nag_dtr_load (f16qgc)

NAG Library Function Document nag_dsytrf (f07mdc)

NAG Library Function Document nag_dtrmv (f16pfc)

NAG Library Function Document nag_dstev (f08jac)

NAG Library Function Document nag_ztbcon (f07vuc)

NAG Library Function Document nag_dspsv (f07pac)

NAG Library Function Document nag_dpbtrf (f07hdc)

NAG Library Function Document nag_dgelsd (f08kcc)

NAG Library Function Document nag_dsymv (f16pcc)

NAG Library Function Document nag_zgelss (f08knc)

NAG Library Function Document nag_zgelsy (f08bnc)

NAG Library Function Document nag_zhpr2 (f16ssc)

NAG Library Function Document nag_dsygv (f08sac)

NAG Library Function Document nag_zhpev (f08gnc)

NAG Fortran Library Routine Document F04BGF.1

NAG C Library Function Document nag_dgbtrs (f07bec)

NAG Library Function Document nag_ztzrzf (f08bvc)

NAG Library Function Document nag_dsbev (f08hac)

NAG Library Function Document nag_zheevx (f08fpc)

NAG Library Function Document nag_real_gen_matrix_exp (f01ecc)

NAG Library Function Document nag_rgsn_matrix_multi_normal (g05lyc)

NAG Library Function Document nag_asian_geom_price (s30sac)

NAG Library Function Document nag_all_regsn (g02eac)

NAG Library Function Document nag_real_cholesky_skyline_solve (f04mcc)

NAG Library Routine Document F04BEF.1

NAG Library Function Document nag_rngs_copula_students_t (g05rbc)

NAG C Library Function Document nag_zsytri (f07nwc)

NAG Library Function Document nag_zhbevx (f08hpc)

NAG Library Function Document nag_dgetrf (f07adc)

NAG Library Function Document nag_rngs_varma_time_series (g05pcc)

NAG C Library Function Document nag_binary_factor_service (g11sbc)

NAG Library Function Document nag_dtpttr (f01vcc)

NAG C Library Function Document nag_zgemv (f16sac)

NAG C Library Function Document nag_zger (f16smc)

NAG C Library Function Document nag_dgemv (f16pac)

NAG Library Function Document nag_dger (f16pmc)

NAG Library Function Document nag_ztgsen (f08yuc)

NAG Library Function Document nag_dtrttf (f01vec)

NAG Fortran Library Routine Document F04CAF.1

NAG C Library Function Document nag_zspcon (f07quc)

NAG Library Function Document nag_zpbequ (f07htc)

NAG Library Function Document nag_mv_ordinal_multidimscale (g03fcc)

NAG C Library Function Document nag_zhemv (f16scc)

NAG Library Function Document nag_superlu_diagnostic_lu (f11mmc)

NAG Library Function Document nag_ztrttf (f01vfc)

NAG Library Function Document nag_prob_lin_non_central_chi_sq (g01jcc)

NAG Library Function Document nag_matop_complex_gen_matrix_cond_sqrt (f01kdc)

NAG Library Function Document nag_rand_copula_clayton (g05rhc)

NAG C Library Function Document nag_dspcon (f07pgc)

NAG Fortran Library Routine Document F04BJF.1

NAG Library Function Document nag_dgges (f08xac)

NAG C Library Function Document nag_zhbmv (f16sdc)

NAG Library Function Document nag_1d_cheb_fit_constr (e02agc)

NAG Fortran Library Routine Document F04CJF.1

NAG Library Function Document nag_dtfttp (f01vlc)

NAG Library Function Document nag_dspr (f16pqc)

NAG Library Function Document nag_kruskal_wallis_test (g08afc)

NAG Library Function Document nag_ztfttp (f01vmc)

NAG Fortran Library Routine Document F04DHF.1

NAG C Library Function Document nag_dgbmv (f16pbc)

NAG Library Function Document nag_zsymv (f16tac)

NAG Library Function Document nag_mv_distance_mat (g03eac)

NAG C Library Function Document nag_dsbmv (f16pdc)

NAG Library Function Document nag_asian_geom_greeks (s30sbc)

NAG Library Function Document nag_rand_bivariate_copula_frank (g05rfc)

NAG C Library Function Document nag_zhpmv (f16sec)

NAG Library Function Document nag_dtpsv (f16plc)

NAG Library Function Document nag_bsm_greeks (s30abc)

NAG Library Function Document nag_matop_complex_gen_matrix_fun_num (f01flc)

NAG Library Function Document nag_mv_discrim (g03dac)

NAG Library Function Document nag_dgb_norm (f16rbc)

NAG Library Function Document nag_1d_cheb_intg (e02ajc)

NAG Library Function Document. nag_matop_real_gen_matrix_cond_num

NAG Library Function Document nag_matop_real_gen_matrix_fun_num (f01elc)

NAG Library Function Document. nag_matop_complex_gen_matrix_cond_num

NAG Library Function Document nag_zhfrk (f16zqc)

NAG C Library Function Document nag_linf_fit (e02gcc)

NAG Library Function Document nag_zggesx (f08xpc)

NAG Library Function Document nag_real_symm_sparse_eigensystem_init (f12fac)

NAG Library Function Document nag_zhpr2 (f16ssc)

NAG Library Function Document nag_dgbmv (f16pbc)

NAG Library Function Document nag_superlu_lu_factorize (f11mec)

NAG Library Function Document nag_tsa_multi_part_lag_corr (g13dnc)

NAG Library Function Document nag_mesh2d_inc (d06aac)

NAG Library Function Document nag_corr_cov (g02bxc)

NAG Library Function Document nag_partial_corr (g02byc)

NAG Library Function Document nag_real_symm_sparse_eigensystem_sol (f12fcc)

NAG Library Function Document nag_rand_2_way_table (g05pzc)

NAG Library Function Document nag_dummy_vars (g04eac)

NAG Library Function Document nag_zero_nonlin_eqns_deriv_1 (c05ubc)

NAG Library Function Document nag_glm_tran_model (g02gkc)

NAG Library Function Document nag_mldwt_2d (c09ecc)

NAG Library Function Document nag_smooth_spline_fit (g10abc)

Transcription:

Purpose NAG Library Function Document nag_real_sym_posdef_tridiag_lin_solve () nag_real_sym_posdef_tridiag_lin_solve () computes the solution to a real system of linear equations AX ¼ B, where A is an n by n symmetric positive-definite tridiagonal matrix and X and B are n by r matrices. An estimate of the condition number of A and an error bound for the computed solution are also returned. 2 Specification #include <nag.h> #include <nagf04.h> void nag_real_sym_posdef_tridiag_lin_solve (Nag_OrderType order, Integer n, Integer nrhs, double d[], double e[], double b[], Integer pdb, double *rcond, double *errbnd, NagError *fail) 3 Description A is factorized as A ¼ LDL T, where L is a unit lower bidiagonal matrix and D is diagonal, and the factored form of A is then used to solve the system of equations. 4 References Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (999) LAPACK Users Guide (3rd Edition) SIAM, Philadelphiahttp://www.netlib.org/lapack/lug Higham N J (2002) Accuracy and Stability of Numerical Algorithms (2nd Edition) SIAM, Philadelphia 5 Arguments : order Nag_OrderType Input On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., rowmajor ordering or column-major ordering. C language defined storage is specified by order ¼ Nag_RowMajor. See Section 3.2..3 in the Essential Introduction for a more detailed explanation of the use of this argument. Constraint: order ¼ Nag_RowMajor or Nag_ColMajor. 2: n Integer Input On entry: the number of linear equations n, i.e., the order of the matrix A. Constraint: n 0. 3: nrhs Integer Input On entry: the number of right-hand sides r, i.e., the number of columns of the matrix B. Constraint: nrhs 0. 4: d½dimš double Input/Output Note: the dimension, dim, of the array d must be at least maxð; nþ. On entry: must contain the n diagonal elements of the tridiagonal matrix A..

NAG Library Manual On exit: if fail:code ¼ NE_NOERROR or NE_RCOND, d is overwritten by the n diagonal elements of the diagonal matrix D from the LDL T factorization of A. 5: e½dimš double Input/Output Note: the dimension, dim, of the array e must be at least maxð; n Þ. On entry: must contain the ðn Þ subdiagonal elements of the tridiagonal matrix A. On exit: if fail:code ¼ NE_NOERROR or NE_RCOND, e is overwritten by the ðn Þ subdiagonal elements of the unit lower bidiagonal matrix L from the LDL T factorization of A. (e can also be regarded as the superdiagonal of the unit upper bidiagonal factor U from the U T DU factorization of A.) 6: b½dimš double Input/Output Note: the dimension, dim, of the array b must be at least maxð; pdb nrhsþ when order ¼ Nag_ColMajor; maxð; pdb nþ when order ¼ Nag_RowMajor. The ði; jþth element of the matrix B is stored in b½ðj Þpdb þ i Š when order ¼ Nag_ColMajor; b½ði Þpdb þ j Š when order ¼ Nag_RowMajor. On entry: the n by r matrix of right-hand sides B. On exit: iffail:code ¼ NE_NOERROR or NE_RCOND, the n by r solution matrix X. 7: pdb Integer Input On entry: the stride separating matrix row or column elements (depending on the value of order) in b. Constraints: if order ¼ Nag_ColMajor, pdb maxð; nþ; if order ¼ Nag_RowMajor, pdb maxð; nrhsþ. 8: rcond double * Output On exit: if fail:code ¼ NE_NOERROR or NE_RCOND, an estimate of the reciprocal of the condition number of the matrix A, computed as rcond ¼ = kak A. 9: errbnd double * Output On exit: iffail:code ¼ NE_NOERROR or NE_RCOND, an estimate of the forward error bound for a computed solution ^x, such that k^x xk = kxk errbnd, where ^x is a column of the computed solution returned in the array b and x is the corresponding column of the exact solution X. If rcond is less than machine precision, then errbnd is returned as unity. 0: fail NagError * Input/Output The NAG error argument (see Section 3.6 in the Essential Introduction). 6 Error Indicators and Warnings NE_ALLOC_FAIL Dynamic memory allocation failed. NE_BAD_PARAM On entry, argument hvaluei had an illegal value..2

NE_INT On entry, n ¼ hvaluei. Constraint: n 0. On entry, nrhs ¼ hvaluei. Constraint: nrhs 0. On entry, pdb ¼ hvaluei. Constraint: pdb > 0. NE_INT_2 On entry,pdb ¼ hvaluei, n ¼ hvaluei. Constraint: pdb maxð; nþ. NE_INTERNAL_ERROR An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please consult NAG for assistance. An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance. NE_POS_DEF The principal minor of order hvaluei of the matrix A is not positive-definite. The factorization has not been completed and the solution could not be computed. NE_RCOND A solution has been computed, but rcond is less than machine precision so that the matrix A is numerically singular. 7 Accuracy The computed solution for a single right-hand side, ^x, satisfies an equation of the form ða þ EÞ^x ¼ b, where kek ¼ OðÞA k k and is the machine precision. An approximate error bound for the computed solution is given by k^x xk A ð Þ kek, kxk kak where A ð Þ ¼ A kak, the condition number of A with respect to the solution of the linear equations. nag_real_sym_posdef_tridiag_lin_solve () uses the approximation kek ¼ A k k to estimate errbnd. See Section 4.4 of Anderson et al. (999) for further details. 8 Further Comments The total number of floating-point operations required to solve the equations AX ¼ B is proportional to nr. The condition number estimation requires OðnÞ floating-point operations. See Section 5.3 of Higham (2002) for further details on computing the condition number of tridiagonal matrices. The complex analogue of nag_real_sym_posdef_tridiag_lin_solve () is nag_herm_posdef_tridiag_lin_solve (f04cgc)..3

NAG Library Manual 9 Example This example solves the equations AX ¼ B, where A is the symmetric positive-definite tridiagonal matrix 0 4:0 2:0 0 0 0 2:0 0:0 6:0 0 0 A ¼ 0 6:0 29:0 5:0 0 B C and @ 0 0 5:0 25:0 8:0 A 0 0 0 8:0 5:0 0 6:0 0:0 9:0 4:0 B ¼ 2:0 9:0 B C @ 4:0 65:0 A. 7:0 23:0 An estimate of the condition number of A and an approximate error bound for the computed solutions are also printed. 9. Program Text /* nag_real_sym_posdef_tridiag_lin_solve () Example Program. * * Copyright 2004 Numerical Algorithms Group. * * Mark 8, 2004. */ #include <stdio.h> #include <nag.h> #include <nag_stdlib.h> #include <nagf04.h> #include <nagx04.h> int main(int argc, char *argv[]) FILE *fpin, *fpout; char *outfile = 0; /* Scalars */ double errbnd, rcond; Integer exit_status, i, j, n, nrhs, pdb; /* Arrays */ double *b, *d = 0, *e = 0; /* Nag Types */ NagError fail; Nag_OrderType order; #ifdef NAG_COLUMN_MAJOR #define B(I, J) b[(j-)*pdb + I - ] order = Nag_ColMajor; #else #define B(I, J) b[(i-)*pdb + J - ] order = Nag_RowMajor; #endif #define b_ref(a_, a_2) b[(a_2)*8 + a_ - 9] exit_status = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); fprintf(fpout, "nag_real_sym_posdef_tridiag_lin_solve () Example " "Program Results\n\n"); /* Skip heading in data file */.4

fscanf(fpin, "%ld%ld%*[^\n] ", &n, &nrhs); if (n > 0 && nrhs > 0) /* Allocate memory */ if (!(b = NAG_ALLOC(n*nrhs, double))!(d = NAG_ALLOC(n, double))!(e = NAG_ALLOC(n-, double))) fprintf(fpout, "Allocation failure\n"); exit_status = -; #ifdef NAG_COLUMN_MAJOR pdb = n; #else pdb = nrhs; #endif else fprintf(fpout, "%s\n", "n and/or nrhs too small"); exit_status = ; return exit_status; /* Read A from data file */ for (i = ; i <= n; ++i) fscanf(fpin, "%lf", &d[i-]); for (i = ; i <= n-; ++i) fscanf(fpin, "%lf", &e[i-]); /* Read B from data file */ for (i = ; i <= n; ++i) for (j = ; j <= nrhs; ++j) fscanf(fpin, "%lf", &B(i, j)); /* Solve the equations AX = B for X */ /* nag_real_sym_posdef_tridiag_lin_solve (). * Computes the solution and error-bound to a real symmetric * positive-definite tridiagonal system of linear equations */ nag_real_sym_posdef_tridiag_lin_solve(order, n, nrhs, d, e, b, pdb, &rcond, &errbnd, &fail); if (fail.code == NE_NOERROR) /* Print solution, estimate of condition number and approximate */ /* error bound */ /* nag_gen_real_mat_print (x04cac). * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, nrhs, b, pdb, "Solution", outfile, &fail); if (outfile &&!(fpout = fopen(outfile, "a"))) exit_status = 2;.5

NAG Library Manual if (fail.code!= NE_NOERROR) fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = ; fprintf(fpout, "\n%s\n%6s%0.e\n", "Estimate of condition number", "",.0/rcond); fprintf(fpout, "\n\n"); fprintf(fpout, "%s\n%6s", "Estimate of error bound for computed solutions", ""); fprintf(fpout, "%0.e\n\n", errbnd); else if (fail.code == NE_RCOND) /* Matrix A is numerically singular. Print estimate of */ /* reciprocal of condition number and solution */ fprintf(fpout, "\n"); fprintf(fpout, "%s\n%6s%0.e\n", "Estimate of reciprocal of condition number", "", rcond); fprintf(fpout, "\n\n"); /* nag_gen_real_mat_print (x04cac), see above. */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, nrhs, b, pdb, "Solution", outfile, &fail); if (outfile &&!(fpout = fopen(outfile, "a"))) exit_status = 2; if (fail.code!= NE_NOERROR) fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = ; else if (fail.code == NE_POS_DEF) fprintf(fpout, "%s%3ld%s\n\n", "The leading minor of order ", fail.errnum, " is not positive definite"); else fprintf( fpout, "Error from nag_real_sym_posdef_tridiag_lin_solve ().\n%s\n", fail.message); exit_status = ; END: if (fpin!= stdin) fclose(fpin); if (fpout!= stdout) fclose(fpout); if (b) NAG_FREE(b); if (d) NAG_FREE(d); if (e) NAG_FREE(e); return exit_status;.6

9.2 Program Data nag_real_sym_posdef_tridiag_lin_solve () Example Program Data 5 2 :Values of N and NRHS 4.0 0.0 29.0 25.0 5.0 :End of diagonal D -2.0-6.0 5.0 8.0 :End of sub-diagonal E 6.0 0.0 9.0 4.0 2.0 9.0 4.0 65.0 7.0 23.0 :End of matrix B 9.3 Program Results nag_real_sym_posdef_tridiag_lin_solve () Example Program Results Solution 2 2.5000 2.0000 2 2.0000 -.0000 3.0000-3.0000 4 -.0000 6.0000 5 3.0000-5.0000 Estimate of condition number.e+02 Estimate of error bound for computed solutions.2e-4.7 (last)