⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vectors.texi

📁 该文件为c++的数学函数库!是一个非常有用的编程工具.它含有各种数学函数,为科学计算、工程应用等程序编写提供方便!
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@comment @comment The new vector is only a view of the block underlying the original@comment vector, @var{v}.  The block is not owned by the new vector.  When the new@comment vector is deallocated the original vector @var{v} and its block will@comment continue to exist.  The original memory can only be deallocated by@comment freeing the original vector.  Of course, the original vector should not@comment be deallocated while the new vector is still in use.@comment @end deftypefun@node Copying vectors@subsection Copying vectorsCommon operations on vectors such as addition and multiplication areavailable in the @sc{blas} part of the library (@pxref{BLASSupport}).  However, it is useful to have a small number of utilityfunctions which do not require the full @sc{blas} code.  The followingfunctions fall into this category.@deftypefun int gsl_vector_memcpy (gsl_vector * @var{dest}, const gsl_vector * @var{src})This function copies the elements of the vector @var{src} into thevector @var{dest}.  The two vectors must have the same length.@end deftypefun@deftypefun int gsl_vector_swap (gsl_vector * @var{v}, gsl_vector * @var{w})This function exchanges the elements of the vectors @var{v} and @var{w}by copying.  The two vectors must have the same length.@end deftypefun@node Exchanging elements@subsection Exchanging elementsThe following function can be used to exchange, or permute, the elementsof a vector.@deftypefun int gsl_vector_swap_elements (gsl_vector * @var{v}, size_t @var{i}, size_t @var{j})This function exchanges the @var{i}-th and @var{j}-th elements of thevector @var{v} in-place.@end deftypefun@deftypefun int gsl_vector_reverse (gsl_vector * @var{v})This function reverses the order of the elements of the vector @var{v}.@end deftypefun@node Vector operations@subsection Vector operationsThe following operations are only defined for real vectors.@deftypefun int gsl_vector_add (gsl_vector * @var{a}, const gsl_vector * @var{b})This function adds the elements of vector @var{b} to the elements ofvector @var{a}, @math{a'_i = a_i + b_i}. The two vectors must have thesame length.@end deftypefun@deftypefun int gsl_vector_sub (gsl_vector * @var{a}, const gsl_vector * @var{b})This function subtracts the elements of vector @var{b} from the elements ofvector @var{a}, @math{a'_i = a_i - b_i}. The two vectors must have thesame length.@end deftypefun@deftypefun int gsl_vector_mul (gsl_vector * @var{a}, const gsl_vector * @var{b})This function multiplies the elements of vector @var{a} by the elements ofvector @var{b}, @math{a'_i = a_i * b_i}. The two vectors must have thesame length.@end deftypefun@deftypefun int gsl_vector_div (gsl_vector * @var{a}, const gsl_vector * @var{b})This function divides the elements of vector @var{a} by the elements ofvector @var{b}, @math{a'_i = a_i / b_i}. The two vectors must have thesame length.@end deftypefun@deftypefun int gsl_vector_scale (gsl_vector * @var{a}, const double @var{x})This function multiplies the elements of vector @var{a} by the constantfactor @var{x}, @math{a'_i = x a_i}.@end deftypefun@deftypefun int gsl_vector_add_constant (gsl_vector * @var{a}, const double @var{x})This function adds the constant value @var{x} to the elements of thevector @var{a}, @math{a'_i = a_i + x}.@end deftypefun@node Finding maximum and minimum elements of vectors@subsection Finding maximum and minimum elements of vectors@deftypefun double gsl_vector_max (const gsl_vector * @var{v})This function returns the maximum value in the vector @var{v}.@end deftypefun@deftypefun double gsl_vector_min (const gsl_vector * @var{v})This function returns the minimum value in the vector @var{v}.@end deftypefun@deftypefun void gsl_vector_minmax (const gsl_vector * @var{v}, double * @var{min_out}, double * @var{max_out})This function returns the minimum and maximum values in the vector@var{v}, storing them in @var{min_out} and @var{max_out}.@end deftypefun@deftypefun size_t gsl_vector_max_index (const gsl_vector * @var{v})This function returns the index of the maximum value in the vector @var{v}.When there are several equal maximum elements then the lowest index isreturned.@end deftypefun@deftypefun size_t gsl_vector_min_index (const gsl_vector * @var{v})This function returns the index of the minimum value in the vector @var{v}.When there are several equal minimum elements then the lowest index isreturned.@end deftypefun@deftypefun void gsl_vector_minmax_index (const gsl_vector * @var{v}, size_t * @var{imin}, size_t * @var{imax})This function returns the indices of the minimum and maximum values inthe vector @var{v}, storing them in @var{imin} and @var{imax}. Whenthere are several equal minimum or maximum elements then the lowestindices are returned.@end deftypefun@node Vector properties@subsection Vector properties@deftypefun int gsl_vector_isnull (const gsl_vector * @var{v})This function returns 1 if all the elements of the vector @var{v} arezero, and 0 otherwise.@end deftypefun@node Example programs for vectors@subsection Example programs for vectorsThis program shows how to allocate, initialize and read from a vectorusing the functions @code{gsl_vector_alloc}, @code{gsl_vector_set} and@code{gsl_vector_get}.@example@verbatiminclude examples/vector.c@end example@comment@noindentHere is the output from the program.  The final loop attempts to readoutside the range of the vector @code{v}, and the error is trapped bythe range-checking code in @code{gsl_vector_get}.@examplev_0 = 1.23v_1 = 2.23v_2 = 3.23gsl: vector_source.c:12: ERROR: index out of rangeIOT trap/Abort (core dumped)@end example@comment@noindentThe next program shows how to write a vector to a file.@example@verbatiminclude examples/vectorw.c@end example@comment@noindentAfter running this program the file @file{test.dat} should contain theelements of @code{v}, written using the format specifier@code{%.5g}.  The vector could then be read back in using the function@code{gsl_vector_fscanf (f, v)} as follows:@example@verbatiminclude examples/vectorr.c@end example@node Matrices@section Matrices@cindex matrices@cindex physical dimension, matrices@cindex trailing dimension, matrices@cindex leading dimension, matricesMatrices are defined by a @code{gsl_matrix} structure which describes ageneralized slice of a block.  Like a vector it represents a set ofelements in an area of memory, but uses two indices instead of one.The @code{gsl_matrix} structure contains six components, the twodimensions of the matrix, a physical dimension, a pointer to the memorywhere the elements of the matrix are stored, @var{data}, a pointer tothe block owned by the matrix @var{block}, if any, and an ownershipflag, @var{owner}.  The physical dimension determines the memory layoutand can differ from the matrix dimension to allow the use ofsubmatrices.  The @code{gsl_matrix} structure is very simple and lookslike this,@exampletypedef struct@{  size_t size1;  size_t size2;  size_t tda;  double * data;  gsl_block * block;  int owner;@} gsl_matrix;@end example@comment@noindentMatrices are stored in row-major order, meaning that each row ofelements forms a contiguous block in memory.  This is the standard"C-language ordering" of two-dimensional arrays. Note that @sc{fortran}stores arrays in column-major order. The number of rows is @var{size1}.The range of valid row indices runs from 0 to @code{size1-1}.  Similarly@var{size2} is the number of columns.  The range of valid column indicesruns from 0 to @code{size2-1}.  The physical row dimension @var{tda}, or@dfn{trailing dimension}, specifies the size of a row of the matrix aslaid out in memory.For example, in the following matrix @var{size1} is 3, @var{size2} is 4,and @var{tda} is 8.  The physical memory layout of the matrix begins inthe top left hand-corner and proceeds from left to right along each rowin turn.@example@group00 01 02 03 XX XX XX XX10 11 12 13 XX XX XX XX20 21 22 23 XX XX XX XX@end group@end example@noindentEach unused memory location is represented by ``@code{XX}''.  Thepointer @var{data} gives the location of the first element of the matrixin memory.  The pointer @var{block} stores the location of the memoryblock in which the elements of the matrix are located (if any).  If thematrix owns this block then the @var{owner} field is set to one and theblock will be deallocated when the matrix is freed.  If the matrix isonly a slice of a block owned by another object then the @var{owner} field iszero and any underlying block will not be freed.The functions for allocating and accessing matrices are defined in@file{gsl_matrix.h}@menu* Matrix allocation::           * Accessing matrix elements::   * Initializing matrix elements::  * Reading and writing matrices::  * Matrix views::                * Creating row and column views::  * Copying matrices::            * Copying rows and columns::    * Exchanging rows and columns::  * Matrix operations::           * Finding maximum and minimum elements of matrices::  * Matrix properties::           * Example programs for matrices::  @end menu@node Matrix allocation@subsection Matrix allocationThe functions for allocating memory to a matrix follow the style of@code{malloc} and @code{free}.  They also perform their own errorchecking.  If there is insufficient memory available to allocate a vectorthen the functions call the GSL error handler (with an error number of@code{GSL_ENOMEM}) in addition to returning a null pointer.  Thus if youuse the library error handler to abort your program then it isn'tnecessary to check every @code{alloc}.@deftypefun {gsl_matrix *} gsl_matrix_alloc (size_t @var{n1}, size_t @var{n2})This function creates a matrix of size @var{n1} rows by @var{n2}columns, returning a pointer to a newly initialized matrix struct. A newblock is allocated for the elements of the matrix, and stored in the@var{block} component of the matrix struct.  The block is ``owned'' by thematrix, and will be deallocated when the matrix is deallocated.@end deftypefun@deftypefun {gsl_matrix *} gsl_matrix_calloc (size_t @var{n1}, size_t @var{n2})This function allocates memory for a matrix of size @var{n1} rows by@var{n2} columns and initializes all the elements of the matrix to zero.@end deftypefun@deftypefun void gsl_matrix_free (gsl_matrix * @var{m})This function frees a previously allocated matrix @var{m}.  If thematrix was created using @code{gsl_matrix_alloc} then the blockunderlying the matrix will also be deallocated.  If the matrix has beencreated from another object then the memory is still owned by thatobject and will not be deallocated.@end deftypefun@node Accessing matrix elements@subsection Accessing matrix elements@cindex matrices, range-checking@cindex range-checking for matricesThe functions for accessing the elements of a matrix use the same rangechecking system as vectors.  You can turn off range checking by recompilingyour program with the preprocessor definition@code{GSL_RANGE_CHECK_OFF}.The elements of the matrix are stored in "C-order", where the secondindex moves continuously through memory.  More precisely, the elementaccessed by the function @code{gsl_matrix_get(m,i,j)} and@code{gsl_matrix_set(m,i,j,x)} is 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -