📄 vectors.texi
字号:
@comment existing view in @var{m} will be lost as a result of this function.
@comment @end deftypefun
@comment
@comment @deftypefun int gsl_matrix_view_from_array (gsl_matrix * @var{m}, double * @var{base}, const size_t @var{offset}, const size_t @var{n1}, const size_t @var{n2})
@comment This function modifies and existing matrix view @var{m} to form a new
@comment view of an array @var{base}, starting from element @var{offset}. The
@comment matrix has @var{n1} rows and @var{n2} columns. Any
@comment existing view in @var{m} will be lost as a result of this function.
@comment @end deftypefun
@comment
@comment @deftypefun {gsl_matrix *} gsl_matrix_alloc_from_block (gsl_block * @var{b}, size_t @var{offset}, size_t @var{n1}, size_t @var{n2}, size_t @var{tda})
@comment This function creates a matrix as a slice of the block @var{b},
@comment returning a pointer to a newly initialized matrix struct. The start of
@comment the matrix is offset by @var{offset} elements from the start of the
@comment block. The matrix has @var{n1} rows and @var{n2} columns, with the
@comment physical number of columns in memory given by @var{tda}.
@comment Mathematically, the (@var{i},@var{j})-th element of the matrix is given by,
@comment
@comment @example
@comment m(i,j) = b->data[offset + i*tda + j]
@comment @end example
@comment @noindent
@comment where the index @var{i} runs from 0 to @code{n1-1} and the index @var{j}
@comment runs from 0 to @code{n2-1}.
@comment
@comment A null pointer is returned if the combined parameters
@comment (@var{offset},@var{n1},@var{n2},@var{tda}) overrun the end of the block
@comment or if insufficient memory is available to store the matrix.
@comment
@comment The matrix is only a view of the block @var{b}, and the block is not
@comment owned by the matrix. When the matrix is deallocated the block @var{b}
@comment will continue to exist. This memory can only be deallocated by freeing
@comment the block itself. Of course, this block should not be deallocated while
@comment the matrix is still in use.
@comment @end deftypefun
@comment
@comment @deftypefun {gsl_matrix *} gsl_matrix_alloc_from_matrix (gsl_matrix * @var{m}, size_t @var{k1}, size_t @var{k2}, size_t @var{n1}, size_t @var{n2})
@comment
@comment This function creates a matrix as a submatrix of the matrix @var{m},
@comment returning a pointer to a newly initialized matrix struct. The upper-left
@comment element of the submatrix is the element (@var{k1},@var{k2}) of the
@comment original matrix. The submatrix has @var{n1} rows and @var{n2} columns.
@comment The physical number of columns in memory given by @var{tda} is
@comment unchanged. Mathematically, the (@var{i},@var{j})-th element of the
@comment new matrix is given by,
@comment
@comment @example
@comment m'(i,j) = m->data[(k1*m->tda + k2) + i*m->tda + j]
@comment @end example
@comment @noindent
@comment where the index @var{i} runs from 0 to @code{n1-1} and the index @var{j}
@comment runs from 0 to @code{n2-1}.
@comment
@comment A null pointer is returned if the combined parameters
@comment (@var{k1},@var{k2},@var{n1},@var{n2},@var{tda}) overrun the end of the
@comment original matrix or if insufficient memory is available to store the matrix.
@comment
@comment The new matrix is only a view of the block underlying the existing
@comment matrix, @var{m}. The block is not owned by the new matrix. When the new
@comment matrix is deallocated the original matrix @var{m} and its block will
@comment continue to exist. The original memory can only be deallocated by
@comment freeing the original matrix. Of course, the original matrix should not
@comment be deallocated while the new matrix is still in use.
@comment @end deftypefun
@node Creating row and column views
@subsection Creating row and column views
In general there are two ways to access an object, by reference or by
copying. The functions described in this section create vector views
which allow access to a row or column of a matrix by reference.
Modifying elements of the view is equivalent to modifying the matrix,
since both the vector view and the matrix point to the same memory
block.
@deftypefun gsl_vector_view gsl_matrix_row (gsl_matrix * @var{m}, size_t @var{i})
@deftypefunx {gsl_vector_const_view} gsl_matrix_const_row (const gsl_matrix * @var{m}, size_t @var{i})
These functions return a vector view of the @var{i}-th row of the matrix
@var{m}. The @code{data} pointer of the new vector is set to null if
@var{i} is out of range.
The function @code{gsl_vector_const_row} is equivalent to
@code{gsl_matrix_row} but can be used for matrices which are declared
@code{const}.
@end deftypefun
@deftypefun gsl_vector_view gsl_matrix_column (gsl_matrix * @var{m}, size_t @var{j})
@deftypefunx {gsl_vector_const_view} gsl_matrix_const_column (const gsl_matrix * @var{m}, size_t @var{j})
These functions return a vector view of the @var{j}-th column of the
matrix @var{m}. The @code{data} pointer of the new vector is set to
null if @var{j} is out of range.
The function @code{gsl_vector_const_column} equivalent to
@code{gsl_matrix_column} but can be used for matrices which are declared
@code{const}.
@end deftypefun
@deftypefun gsl_vector_view gsl_matrix_diagonal (gsl_matrix * @var{m})
@deftypefunx {gsl_vector_const_view} gsl_matrix_const_diagonal (const gsl_matrix * @var{m})
These functions returns a vector view of the diagonal of the matrix
@var{m}. The matrix @var{m} is not required to be square. For a
rectangular matrix the length of the diagonal is the same as the smaller
dimension of the matrix.
The function @code{gsl_matrix_const_diagonal} is equivalent to
@code{gsl_matrix_diagonal} but can be used for matrices which are
declared @code{const}.
@end deftypefun
@deftypefun gsl_vector_view gsl_matrix_subdiagonal (gsl_matrix * @var{m}, size_t @var{k})
@deftypefunx {gsl_vector_const_view} gsl_matrix_const_subdiagonal (const gsl_matrix * @var{m}, size_t @var{k})
These functions return a vector view of the @var{k}-th subdiagonal of
the matrix @var{m}. The matrix @var{m} is not required to be square.
The diagonal of the matrix corresponds to @math{k = 0}.
The function @code{gsl_matrix_const_subdiagonal} is equivalent to
@code{gsl_matrix_subdiagonal} but can be used for matrices which are
declared @code{const}.
@end deftypefun
@deftypefun gsl_vector_view gsl_matrix_superdiagonal (gsl_matrix * @var{m}, size_t @var{k})
@deftypefunx {gsl_vector_const_view} gsl_matrix_const_superdiagonal (const gsl_matrix * @var{m}, size_t @var{k})
These functions return a vector view of the @var{k}-th superdiagonal of
the matrix @var{m}. The matrix @var{m} is not required to be square. The
diagonal of the matrix corresponds to @math{k = 0}.
The function @code{gsl_matrix_const_superdiagonal} is equivalent to
@code{gsl_matrix_superdiagonal} but can be used for matrices which are
declared @code{const}.
@end deftypefun
@comment @deftypefun {gsl_vector *} gsl_vector_alloc_row_from_matrix (gsl_matrix * @var{m}, size_t @var{i})
@comment This function allocates a new @code{gsl_vector} struct which points to
@comment the @var{i}-th row of the matrix @var{m}.
@comment @end deftypefun
@comment
@comment @deftypefun {gsl_vector *} gsl_vector_alloc_col_from_matrix (gsl_matrix * @var{m}, size_t @var{j})
@comment This function allocates a new @code{gsl_vector} struct which points to
@comment the @var{j}-th column of the matrix @var{m}.
@comment @end deftypefun
@node Copying matrices
@subsection Copying matrices
@deftypefun int gsl_matrix_memcpy (gsl_matrix * @var{dest}, const gsl_matrix * @var{src})
This function copies the elements of the matrix @var{src} into the
matrix @var{dest}. The two matrices must have the same size.
@end deftypefun
@deftypefun int gsl_matrix_swap (gsl_matrix * @var{m1}, gsl_matrix * @var{m2})
This function exchanges the elements of the matrices @var{m1} and
@var{m2} by copying. The two matrices must have the same size.
@end deftypefun
@node Copying rows and columns
@subsection Copying rows and columns
The functions described in this section copy a row or column of a matrix
into a vector. This allows the elements of the vector and the matrix to
be modified independently. Note that if the matrix and the vector point
to overlapping regions of memory then the result will be undefined. The
same effect can be achieved with more generality using
@code{gsl_vector_memcpy} with vector views of rows and columns.
@deftypefun int gsl_matrix_get_row (gsl_vector * @var{v}, const gsl_matrix * @var{m}, size_t @var{i})
This function copies the elements of the @var{i}-th row of the matrix
@var{m} into the vector @var{v}. The length of the vector must be the
same as the length of the row.
@end deftypefun
@deftypefun int gsl_matrix_get_col (gsl_vector * @var{v}, const gsl_matrix * @var{m}, size_t @var{j})
This function copies the elements of the @var{j}-th column of the matrix
@var{m} into the vector @var{v}. The length of the vector must be the
same as the length of the column.
@end deftypefun
@deftypefun int gsl_matrix_set_row (gsl_matrix * @var{m}, size_t @var{i}, const gsl_vector * @var{v})
This function copies the elements of the vector @var{v} into the
@var{i}-th row of the matrix @var{m}. The length of the vector must be
the same as the length of the row.
@end deftypefun
@deftypefun int gsl_matrix_set_col (gsl_matrix * @var{m}, size_t @var{j}, const gsl_vector * @var{v})
This function copies the elements of the vector @var{v} into the
@var{j}-th column of the matrix @var{m}. The length of the vector must be
the same as the length of the column.
@end deftypefun
@node Exchanging rows and columns
@subsection Exchanging rows and columns
The following functions can be used to exchange the rows and columns of
a matrix.
@deftypefun int gsl_matrix_swap_rows (gsl_matrix * @var{m}, size_t @var{i}, size_t @var{j})
This function exchanges the @var{i}-th and @var{j}-th rows of the matrix
@var{m} in-place.
@end deftypefun
@deftypefun int gsl_matrix_swap_columns (gsl_matrix * @var{m}, size_t @var{i}, size_t @var{j})
This function exchanges the @var{i}-th and @var{j}-th columns of the
matrix @var{m} in-place.
@end deftypefun
@deftypefun int gsl_matrix_swap_rowcol (gsl_matrix * @var{m}, size_t @var{i}, size_t @var{j})
This function exchanges the @var{i}-th row and @var{j}-th column of the
matrix @var{m} in-place. The matrix must be square for this operation to
be possible.
@end deftypefun
@deftypefun int gsl_matrix_transpose_memcpy (gsl_matrix * @var{dest}, const gsl_matrix * @var{src})
This function makes the matrix @var{dest} the transpose of the matrix
@var{src} by copying the elements of @var{src} into @var{dest}. This
function works for all matrices provided that the dimensions of the matrix
@var{dest} match the transposed dimensions of the matrix @var{src}.
@end deftypefun
@deftypefun int gsl_matrix_transpose (gsl_matrix * @var{m})
This function replaces the matrix @var{m} by its transpose by copying
the elements of the matrix in-place. The matrix must be square for this
operation to be possible.
@end deftypefun
@node Matrix operations
@subsection Matrix operations
The following operations are defined for real and complex matrices.
@deftypefun int gsl_matrix_add (gsl_matrix * @var{a}, const gsl_matrix * @var{b})
This function adds the elements of matrix @var{b} to the elements of
matrix @var{a}, @math{a'(i,j) = a(i,j) + b(i,j)}. The two matrices must have the
same dimensions.
@end deftypefun
@deftypefun int gsl_matrix_sub (gsl_matrix * @var{a}, const gsl_matrix * @var{b})
This function subtracts the elements of matrix @var{b} from the elements of
matrix @var{a}, @math{a'(i,j) = a(i,j) - b(i,j)}. The two matrices must have the
same dimensions.
@end deftypefun
@deftypefun int gsl_matrix_mul_elements (gsl_matrix * @var{a}, const gsl_matrix * @var{b})
This function multiplies the elements of matrix @var{a} by the elements of
matrix @var{b}, @math{a'(i,j) = a(i,j) * b(i,j)}. The two matrices must have the
same dimensions.
@end deftypefun
@deftypefun int gsl_matrix_div_elements (gsl_matrix * @var{a}, const gsl_matrix * @var{b})
This function divides the elements of matrix @var{a} by the elements of
matrix @var{b}, @math{a'(i,j) = a(i,j) / b(i,j)}. The two matrices must have the
same dimensions.
@end deftypefun
@deftypefun int gsl_matrix_scale (gsl_matrix * @var{a}, const double @var{x})
This function multiplies the elements of matrix @var{a} by the constant
factor @var{x}, @math{a'(i,j) = x a(i,j)}.
@end deftypefun
@deftypefun int gsl_matrix_add_constant (gsl_matrix * @var{a}, const double @var{x})
This function adds the constant value @var{x} to the elements of the
matrix @var{a}, @math{a'(i,j) = a(i,j) + x}.
@end deftypefun
@node Finding maximum and minimum elements of matrices
@subsection Finding maximum and minimum elements of matrices
The following operations are only defined for real matrices.
@deftypefun double gsl_matrix_max (const gsl_matrix * @var{m})
This function returns the maximum value in the matrix @var{m}.
@end deftypefun
@deftypefun double gsl_matrix_min (const gsl_matrix * @var{m})
This function returns the minimum value in the matrix @var{m}.
@end deftypefun
@deftypefun void gsl_matrix_minmax (const gsl_matrix * @var{m}, double * @var{min_out}, double * @var{max_out})
This function returns the minimum and maximum values in the matrix
@var{m}, storing them in @var{min_out} and @var{max_out}.
@end deftypefun
@deftypefun void gsl_matrix_max_index (const gsl_matrix * @var{m}, size_t * @var{imax}, size_t * @var{jmax})
This function returns the indices of the maximum value in the matrix
@var{m}, storing them in @var{imax} and @var{jmax}. When there are
several equal maximum elements then the first element found is returned,
searching in row-major order.
@end deftypefun
@deftypefun void gsl_matrix_min_index (const gsl_matrix * @var{m}, size_t * @var{imax}, size_t * @var{jmax})
This function returns the indices of the minimum value in t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -