正在加载图片...
1.2 Some C Conventions for Scientific Computing 21 [0][0 0][1] [0][2] 0][3] 0][4] 1][0 1][1] 1][2 1][3 1][4] [2][0] [2][1] [2][2] 2][3] 2][4] (a) http://www.nr. 83g *m[0] [0][0 [0][1] [0][2] 0][3] [0][4] granted for 100 (including this one) 19881992 -872 *m[1] [1][0] [1][1] [1][2] 1][3] [1][4] to any from NUMERICAL RECIPES IN by Cambridge (Nort *m[2] 2][0 2][1 2][2 2][3] 2][4] (b) America server computer, users to make one paper UnN电.t THE Figure 1.2.1.Two storage schemes for a matrix m.Dotted lines denote address reference, while solid ART lines connect sequential memory locations.(a)Pointer to a fixed size two-dimensional array.(b)Pointer to an array of pointers to rows;this is the scheme adopted in this book 9 Programs float a[13][9],**aa; int i; aa=(float **malloc((unsigned)13*sizeof(float*)); for(i=0;i<=12;i+)aa[i]=a[i]; a[i]is a pointer to a[i][o] to dir The identifier aa is now a matrix with index range aa [0..12][0..8].You can use OF SCIENTIFIC COMPUTING (ISBN or modify its elements ad lib,and more importantly you can pass it as an argument 1988.1820 to any function by its name aa.That function,which declares the corresponding dummy argument as float **aa;,can address its elements as aa [i][i]without v@cam knowing its physical size. .Further reproduction, 10-621 You may rightly not wish to clutter your programs with code like the above fragment.Also,there is still the outstanding problem of how to treat unit-offset Numerical Recipes 431085 indices,so that(for example)the above matrix aa could be addressed with the range a[1..13][1..9].Both of these problems are solved by additional utility routines (outside in nrutil.c(Appendix B)which allocate and deallocate matrices of arbitrary range. North Software. The synopses are Ame float **matrix(long nrl,long nrh,long ncl,long nch) Allocates a float matrix with range [nrl..nrh][ncl..nch]. double **dmatrix(long nrl,long nrh,long ncl,long nch) Allocates a double matrix with range [nrl..nrh][ncl..nch]. int **imatrix(long nrl,long nrh,long ncl,long nch) Allocates an int matrix with range [nrl..nrh][ncl..nch]. void free_matrix(float **m,long nrl,long nrh,long ncl,long nch) Frees a matrix allocated with matrix1.2 Some C Conventions for Scientific Computing 21 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). [0][0] [0][1] [0][2] [0][3] [0][4] [1][0] [1][1] [1][2] [1][3] [1][4] [0][0] [0][1] [0][2] [0][3] [0][4] [1][0] [1][1] [1][2] [1][3] [1][4] [2][0] [2][1] [2][2] [2][3] [2][4] [2][0] [2][1] [2][2] [2][3] [2][4] *m[0] *m[1] *m[2] **m **m (a) (b) Figure 1.2.1. Two storage schemes for a matrix m. Dotted lines denote address reference, while solid lines connect sequential memory locations. (a) Pointer to a fixed size two-dimensional array. (b) Pointer to an array of pointers to rows; this is the scheme adopted in this book. float a[13][9],**aa; int i; aa=(float **) malloc((unsigned) 13*sizeof(float*)); for(i=0;i<=12;i++) aa[i]=a[i]; a[i] is a pointer to a[i][0] The identifier aa is now a matrix with index range aa[0..12][0..8]. You can use or modify its elements ad lib, and more importantly you can pass it as an argument to any function by its name aa. That function, which declares the corresponding dummy argument as float **aa;, can address its elements as aa[i][j] without knowing its physical size. You may rightly not wish to clutter your programs with code like the above fragment. Also, there is still the outstanding problem of how to treat unit-offset indices, so that (for example) the above matrix aa could be addressed with the range a[1..13][1..9]. Both of these problems are solved by additional utility routines in nrutil.c (Appendix B) which allocate and deallocate matrices of arbitrary range. The synopses are float **matrix(long nrl, long nrh, long ncl, long nch) Allocates a float matrix with range [nrl..nrh][ncl..nch]. double **dmatrix(long nrl, long nrh, long ncl, long nch) Allocates a double matrix with range [nrl..nrh][ncl..nch]. int **imatrix(long nrl, long nrh, long ncl, long nch) Allocates an int matrix with range [nrl..nrh][ncl..nch]. void free_matrix(float **m, long nrl, long nrh, long ncl, long nch) Frees a matrix allocated with matrix
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有