NAG Library Function Document nag_dgetri (f07ajc)

Similar documents
NAG Library Function Document nag_dtr_load (f16qgc)

NAG Library Function Document nag_dtrsyl (f08qhc)

NAG Library Function Document nag_complex_gen_lin_solve (f04cac)

NAG Library Function Document nag_dsytrf (f07mdc)

NAG Library Function Document nag_real_sym_posdef_tridiag_lin_solve (f04bgc)

NAG Library Function Document nag_dtrmv (f16pfc)

NAG Library Function Document nag_dgglse (f08zac)

NAG Library Function Document nag_herm_posdef_tridiag_lin_solve (f04cgc)

NAG Library Function Document nag_complex_tridiag_lin_solve (f04ccc)

NAG C Library Function Document nag_zsytri (f07nwc)

NAG Library Function Document nag_dsymv (f16pcc)

NAG Library Function Document nag_dgetrf (f07adc)

NAG Library Function Document nag_dpbtrf (f07hdc)

NAG Library Function Document nag_ztbcon (f07vuc)

NAG Library Function Document nag_zhpr2 (f16ssc)

NAG Library Function Document nag_real_gen_matrix_exp (f01ecc)

NAG Library Function Document nag_superlu_diagnostic_lu (f11mmc)

NAG Library Function Document nag_dtpttr (f01vcc)

NAG Library Function Document nag_dtrttf (f01vec)

NAG Library Function Document nag_dgttrs (f07cec)

NAG Library Function Document nag_dger (f16pmc)

NAG Library Function Document nag_ztrttf (f01vfc)

NAG Library Function Document nag_rngs_copula_students_t (g05rbc)

NAG Library Function Document nag_all_regsn (g02eac)

NAG Library Function Document nag_rgsn_matrix_multi_normal (g05lyc)

NAG C Library Function Document nag_zger (f16smc)

NAG Library Function Document nag_asian_geom_price (s30sac)

NAG C Library Function Document nag_zgemv (f16sac)

NAG C Library Function Document nag_dgemv (f16pac)

NAG C Library Function Document nag_dgbtrs (f07bec)

NAG Library Function Document nag_rngs_varma_time_series (g05pcc)

NAG C Library Function Document nag_zhemv (f16scc)

NAG C Library Function Document nag_binary_factor_service (g11sbc)

NAG Library Function Document nag_1d_cheb_fit_constr (e02agc)

NAG Library Function Document nag_zgelsy (f08bnc)

NAG Library Function Document nag_dgelsd (f08kcc)

NAG Library Function Document nag_prob_lin_non_central_chi_sq (g01jcc)

NAG C Library Function Document nag_zspcon (f07quc)

NAG Library Function Document nag_zsymv (f16tac)

NAG Library Function Document nag_rand_copula_clayton (g05rhc)

NAG Library Function Document nag_zgelss (f08knc)

NAG Library Function Document nag_ztzrzf (f08bvc)

NAG Library Function Document nag_dspsv (f07pac)

NAG C Library Function Document nag_dspcon (f07pgc)

NAG Library Function Document nag_zhfrk (f16zqc)

NAG Library Function Document nag_matop_complex_gen_matrix_fun_num (f01flc)

NAG Library Function Document nag_dstev (f08jac)

NAG Library Function Document nag_dsygv (f08sac)

NAG Library Function Document nag_zheevx (f08fpc)

NAG Library Function Document nag_dtfttp (f01vlc)

NAG Library Function Document nag_rand_bivariate_copula_frank (g05rfc)

NAG Library Function Document nag_real_cholesky_skyline_solve (f04mcc)

NAG Library Function Document nag_ztfttp (f01vmc)

NAG Library Function Document nag_dspr (f16pqc)

NAG Library Function Document nag_superlu_lu_factorize (f11mec)

NAG Library Function Document nag_zhpev (f08gnc)

NAG Library Function Document nag_asian_geom_greeks (s30sbc)

NAG Library Function Document nag_mv_ordinal_multidimscale (g03fcc)

NAG Library Function Document nag_1d_cheb_intg (e02ajc)

NAG Library Function Document nag_matop_real_gen_matrix_fun_num (f01elc)

NAG Library Function Document nag_mv_distance_mat (g03eac)

NAG Library Function Document nag_zpbequ (f07htc)

NAG Library Function Document nag_dgb_norm (f16rbc)

NAG Library Function Document nag_bsm_greeks (s30abc)

NAG Library Function Document nag_matop_complex_gen_matrix_cond_sqrt (f01kdc)

NAG C Library Function Document nag_zhpmv (f16sec)

NAG Library Function Document nag_dtpsv (f16plc)

NAG C Library Function Document nag_linf_fit (e02gcc)

NAG Library Function Document nag_kruskal_wallis_test (g08afc)

NAG C Library Function Document nag_zhbmv (f16sdc)

NAG Library Function Document. nag_matop_real_gen_matrix_cond_num

NAG Library Function Document nag_mv_discrim (g03dac)

NAG Library Function Document nag_zhpr2 (f16ssc)

NAG Library Function Document. nag_matop_complex_gen_matrix_cond_num

NAG C Library Function Document nag_dgbmv (f16pbc)

NAG Library Function Document nag_dsbev (f08hac)

NAG C Library Function Document nag_dsbmv (f16pdc)

NAG Library Function Document nag_corr_cov (g02bxc)

NAG Library Function Document nag_partial_corr (g02byc)

NAG Library Function Document nag_mesh2d_inc (d06aac)

NAG Library Function Document nag_tsa_multi_part_lag_corr (g13dnc)

NAG Library Function Document nag_rand_2_way_table (g05pzc)

NAG Library Function Document nag_ztgsen (f08yuc)

NAG Library Function Document nag_dgbmv (f16pbc)

NAG Library Function Document nag_2d_spline_eval (e02dec)

NAG Library Function Document nag_dummy_vars (g04eac)

NAG Library Function Document nag_glm_tran_model (g02gkc)

NAG C Library Function Document nag_rngs_varma_time_series (g05pcc)

NAG Library Function Document nag_robust_m_corr_user_fn_no_derr (g02hmc)

NAG Library Function Document nag_mv_cluster_indicator (g03ejc)

NAG Library Function Document nag_real_symm_sparse_eigensystem_sol (f12fcc)

NAG Library Function Document nag_dsf_norm (f16rkc)

NAG Library Function Document nag_real_symm_sparse_eigensystem_init (f12fac)

NAG Library Function Document nag_3d_shep_interp (e01tgc)

NAG Library Function Document nag_smooth_spline_fit (g10abc)

NAG Library Function Document nag_zeros_complex_poly (c02afc)

NAG Library Function Document nag_dgges (f08xac)

NAG Library Function Document nag_zhbevx (f08hpc)

NAG Library Function Document nag_mldwt_2d (c09ecc)

NAG Library Function Document nag_anova_random (g04bbc)

Transcription:

1 Purpose NAG Library Function Document nag_dgetri () nag_dgetri () computes the inverse of a real matrix A, where A has been factorized by nag_dgetrf (f07adc). 2 Specification #include <nag.h> #include <nagf07.h> void nag_dgetri (Nag_OrderType order, Integer n, double a[], Integer pda, const Integer ipiv[], NagError *fail) 3 Description nag_dgetri () is used to compute the inverse of a real matrix A, the function must be preceded by a call to nag_dgetrf (f07adc), which computes the LU factorization of A as A ¼ PLU. The inverse of A is computed by forming U 1 and then solving the equation XPL ¼ U 1 for X. 4 References Du Croz J J and Higham N J (1992) Stability of methods for matrix inversion IMA J. Numer. Anal. 12 1 19 5 Arguments 1: 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.1.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: n, the order of the matrix A. Constraint: n 0. 3: a½dimš double Input/Output Note: the dimension, dim, of the array a must be at least maxð1; pda nþ. The ði; jþth element of the matrix A is stored in a½ðj 1Þpda þ i 1Š when order ¼ Nag_ColMajor; a½ði 1Þpda þ j 1Š when order ¼ Nag_RowMajor. On entry: the LU factorization of A, as returned by nag_dgetrf (f07adc). On exit: the factorization is overwritten by the n by n matrix A 1..1

NAG Library Manual 4: pda Integer Input On entry: the stride separating matrix row or column elements (depending on the value of order) in a. Constraint: pda maxð1; nþ. 5: ipiv½dimš const Integer Input Note: the dimension, dim, of the array ipiv must be at least maxð1; nþ. On entry: the pivot indices, as returned by nag_dgetrf (f07adc). 6: 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 NE_INT On entry, n ¼ hvaluei. Constraint: n 0. On entry, pda ¼ hvaluei. Constraint: pda > 0. hvaluei had an illegal value. NE_INT_2 On entry, pda ¼ hvaluei, n ¼ hvaluei. Constraint: pda maxð1; 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 contact NAG for assistance. NE_SINGULAR Element hvaluei of the diagonal is zero. U is singular, and the inverse of A cannot be computed. 7 Accuracy The computed inverse X satisfies a bound of the form: jxa Ij cn ð ÞX j jpl j jjuj, where cn ð Þ is a modest linear function of n, and is the machine precision. Note that a similar bound for jax Ij cannot be guaranteed, although it is almost always satisfied. See Du Croz and Higham (1992). 8 Further Comments The total number of floating-point operations is approximately 4 3 n3. The complex analogue of this function is nag_zgetri (f07awc)..2

9 Example This example computes the inverse of the matrix A, where 0 1 1:80 2:88 2:05 0:89 5:25 2:95 0:95 3:80 A ¼ B C @ 1:58 2:69 2:90 1:04 A. 1:11 0:66 0:59 0:80 Here A is nonsymmetric and must first be factorized by nag_dgetrf (f07adc). 9.1 Program Text /* nag_dgetri () Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. * Mark 7b revised, 2004. #include <stdio.h> #include <nag.h> #include <nag_stdlib.h> #include <nagf07.h> #include <nagx04.h> int main(int argc, char *argv[]) FILE *fpin, *fpout; char *outfile = 0; /* Scalars Integer i, j, n, pda; Integer exit_status = 0; NagError fail; Nag_OrderType order; /* Arrays double *a = 0; Integer *ipiv = 0; #ifdef NAG_COLUMN_MAJOR #define A(I, J) a[(j-1)*pda + I - 1] order = Nag_ColMajor; #else #define A(I, J) a[(i-1)*pda + J - 1] order = Nag_RowMajor; #endif 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_dgetri () Example Program Results\n\n"); /* Skip heading in data file fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &n); #ifdef NAG_COLUMN_MAJOR pda = n; #else pda = n; #endif /* Allocate memory if (!(a = NAG_ALLOC(n * n, double))!(ipiv = NAG_ALLOC(n, Integer))).3

NAG Library Manual fprintf(fpout, "Allocation failure\n"); exit_status = -1; /* Read A from data file for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &A(i, j)); fscanf(fpin, "%*[^\n] "); /* Factorize A /* nag_dgetrf (f07adc). * LU factorization of real m by n matrix nag_dgetrf(order, n, n, a, pda, ipiv, &fail); fprintf(fpout, "Error from nag_dgetrf (f07adc).\n%s\n", fail.message); /* Compute inverse of A /* nag_dgetri (). * Inverse of real matrix, matrix already factorized by * nag_dgetrf (f07adc) nag_dgetri(order, n, a, pda, ipiv, &fail); fprintf(fpout, "Error from nag_dgetri ().\n%s\n", fail.message); /* Print inverse /* 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, n, a, pda, "Inverse", outfile, &fail); if (outfile &&!(fpout = fopen(outfile, "a"))) exit_status = 2; fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); END: if (fpin!= stdin) fclose(fpin); if (fpout!= stdout) fclose(fpout); if (a) NAG_FREE(a); if (ipiv) NAG_FREE(ipiv); return exit_status;.4

9.2 Program Data nag_dgetri () Example Program Data 4 :Value of N 1.80 2.88 2.05-0.89 5.25-2.95-0.95-3.80 1.58-2.69-2.90-1.04-1.11-0.66-0.59 0.80 :End of matrix A 9.3 Program Results nag_dgetri () Example Program Results Inverse 1 2 3 4 1 1.7720 0.5757 0.0843 4.8155 2-0.1175-0.4456 0.4114-1.7126 3 0.1799 0.4527-0.6676 1.4824 4 2.4944 0.7650-0.0360 7.6119.5 (last)