# 14.9 Class LinAlg¶

- mosek.LinAlg¶
BLAS/LAPACK linear algebra routines.

- Static members
LinAlg.axpy – Computes vector addition and multiplication by a scalar.

LinAlg.dot – Computes the inner product of two vectors.

LinAlg.gemm – Performs a dense matrix multiplication.

LinAlg.gemv – Computes dense matrix times a dense vector product.

LinAlg.potrf – Computes a Cholesky factorization of a dense matrix.

LinAlg.syeig – Computes all eigenvalues of a symmetric dense matrix.

LinAlg.syevd – Computes all the eigenvalues and eigenvectors of a symmetric dense matrix, and thus its eigenvalue decomposition.

LinAlg.syrk – Performs a rank-k update of a symmetric matrix.

- LinAlg.axpy¶
void LinAlg.axpy(int n, double alpha, double[] x, double[] y)

Adds \(\alpha x\) to \(y\), i.e. performs the update

\[y := \alpha x + y.\]Note that the result is stored overwriting \(y\). It must not overlap with the other input arrays.

- Parameters
`n`

(`int`

) – Length of the vectors.`alpha`

(`double`

) – The scalar that multiplies \(x\).`x`

(`double`

[]) – The \(x\) vector.`y`

(`double`

[]) – The \(y\) vector.

- LinAlg.dot¶
double LinAlg.dot(int n, double[] x, double[] y)

Computes the inner product of two vectors \(x,y\) of length \(n\geq 0\), i.e

\[x\cdot y= \sum_{i=1}^n x_i y_i.\]Note that if \(n=0\), then the result of the operation is 0.

- Parameters
`n`

(`int`

) – Length of the vectors.`x`

(`double`

[]) – The \(x\) vector.`y`

(`double`

[]) – The \(y\) vector.

- Return
(

`double`

)

- LinAlg.gemm¶
void LinAlg.gemm(mosek.transpose transa, mosek.transpose transb, int m, int n, int k, double alpha, double[] a, double[] b, double beta, double[] c)

Performs a matrix multiplication plus addition of dense matrices. Given \(A\), \(B\) and \(C\) of compatible dimensions, this function computes

\[C:= \alpha op(A)op(B) + \beta C\]where \(\alpha,\beta\) are two scalar values. The function \(op(X)\) denotes \(X\) if transX is

`NO`

, or \(X^T\) if set to`YES`

. The matrix \(C\) has \(m\) rows and \(n\) columns, and the other matrices must have compatible dimensions.The result of this operation is stored in \(C\). It must not overlap with the other input arrays.

- Parameters
`transa`

(`transpose`

) – Indicates if \(A\) should be transposed. See the Optimizer API documentation for the definition of these constants.`transb`

(`transpose`

) – Indicates if \(B\) should be transposed. See the Optimizer API documentation for the definition of these constants.`m`

(`int`

) – Indicates the number of rows of matrix \(C\).`n`

(`int`

) – Indicates the number of columns of matrix \(C\).`k`

(`int`

) – Specifies the common dimension along which \(op(A)\) and \(op(B)\) are multiplied. For example, if neither \(A\) nor \(B\) are transposed, then this is the number of columns in \(A\) and also the number of rows in \(B\).`alpha`

(`double`

) – A scalar value multiplying the result of the matrix multiplication.`a`

(`double`

[]) – The pointer to the array storing matrix \(A\) in a column-major format.`b`

(`double`

[]) – The pointer to the array storing matrix \(B\) in a column-major format.`beta`

(`double`

) – A scalar value that multiplies \(C\).`c`

(`double`

[]) – The pointer to the array storing matrix \(C\) in a column-major format.

- LinAlg.gemv¶
void LinAlg.gemv(mosek.transpose trans, int m, int n, double alpha, double[] a, double[] x, double beta, double[] y)

Computes the multiplication of a scaled dense matrix times a dense vector, plus a scaled dense vector. Precisely, if

`trans`

is`NO`

then the update is\[y := \alpha A x + \beta y,\]and if

`trans`

is`YES`

then\[y := \alpha A^T x + \beta y,\]where \(\alpha,\beta\) are scalar values and \(A\) is a matrix with \(m\) rows and \(n\) columns.

Note that the result is stored overwriting \(y\). It must not overlap with the other input arrays.

- Parameters
`trans`

(`transpose`

) – Indicates if \(A\) should be transposed. See the Optimizer API documentation for the definition of these constants.`m`

(`int`

) – Specifies the number of rows of the matrix \(A\).`n`

(`int`

) – Specifies the number of columns of the matrix \(A\).`alpha`

(`double`

) – A scalar value multiplying the matrix \(A\).`a`

(`double`

[]) – A pointer to the array storing matrix \(A\) in a column-major format.`x`

(`double`

[]) – A pointer to the array storing the vector \(x\).`beta`

(`double`

) – A scalar value multiplying the vector \(y\).`y`

(`double`

[]) – A pointer to the array storing the vector \(y\).

- LinAlg.potrf¶
void LinAlg.potrf(mosek.uplo uplo, int n, double[] a)

Computes a Cholesky factorization of a real symmetric positive definite dense matrix.

- Parameters
`uplo`

(`uplo`

) – Indicates whether the upper or lower triangular part of the matrix is used. See the Optimizer API documentation for the definition of these constants.`n`

(`int`

) – Specifies the dimension of the symmetric matrix.`a`

(`double`

[]) – A symmetric matrix stored in column-major order. Only the lower or the upper triangular part is used, accordingly with the`uplo`

argument. It will contain the result on exit.

- LinAlg.syeig¶
void LinAlg.syeig(mosek.uplo uplo, int n, double[] a, double[] w)

Computes all eigenvalues of a real symmetric matrix \(A\). Given a matrix \(A\in\real^{n\times n}\) it returns a vector \(w\in\real^n\) containing the eigenvalues of \(A\).

- Parameters
`uplo`

(`uplo`

) – Indicates whether the upper or lower triangular part of the matrix is used. See the Optimizer API documentation for the definition of these constants.`n`

(`int`

) – Specifies the dimension of the symmetric matrix.`a`

(`double`

[]) – A symmetric matrix stored in column-major order. Only the lower or the upper triangular part is used, accordingly with the`uplo`

argument. It will contain the result on exit.`w`

(`double`

[]) – Array of length at least`n`

containing the eigenvalues of \(A\).

- LinAlg.syevd¶
void LinAlg.syevd(mosek.uplo uplo, int n, double[] a, double[] w)

Computes all the eigenvalues and eigenvectors a real symmetric matrix. Given the input matrix \(A\in \real^{n\times n}\), this function returns a vector \(w\in \real^n\) containing the eigenvalues of \(A\) and it also computes the eigenvectors of \(A\). Therefore, this function computes the eigenvalue decomposition of \(A\) as

\[A= U V U^T,\]where \(V=\diag(w)\) and \(U\) contains the eigenvectors of \(A\).

Note that the matrix \(U\) overwrites the input data \(A\).

- Parameters
`uplo`

(`uplo`

) – Indicates whether the upper or lower triangular part of the matrix is used. See the Optimizer API documentation for the definition of these constants.`n`

(`int`

) – Specifies the dimension of the symmetric matrix.`a`

(`double`

[]) – A symmetric matrix stored in column-major order. Only the lower or the upper triangular part is used, accordingly with the`uplo`

argument. It will contain the result on exit.`w`

(`double`

[]) – Array of length at least`n`

containing the eigenvalues of \(A\).

- LinAlg.syrk¶
void LinAlg.syrk(mosek.uplo uplo, mosek.transpose trans, int n, int k, double alpha, double[] a, double beta, double[] c)

Performs a symmetric rank-\(k\) update for a symmetric matrix.

Given a symmetric matrix \(C\in \real^{n\times n}\), two scalars \(\alpha,\beta\) and a matrix \(A\) of rank \(k\leq n\), it computes either

\[C := \alpha A A^T + \beta C,\]when

`trans`

is set to`NO`

and \(A\in \real^{n\times k}\), or\[C := \alpha A^T A + \beta C,\]when

`trans`

is set to`YES`

and \(A\in \real^{k\times n}\).Only the part of \(C\) indicated by

`uplo`

is used and only that part is updated with the result. It must not overlap with the other input arrays.- Parameters
`uplo`

(`uplo`

) – Indicates whether the upper or lower triangular part of \(C\) is used. See the Optimizer API documentation for the definition of these constants.`trans`

(`transpose`

) – Indicates if \(A\) should be transposed. See the Optimizer API documentation for the definition of these constants.`n`

(`int`

) – Specifies the order of \(C\).`k`

(`int`

) – Indicates the number of rows or columns of \(A\), depending on whether or not it is transposed, and its rank.`alpha`

(`double`

) – A scalar value multiplying the result of the matrix multiplication.`a`

(`double`

[]) – The pointer to the array storing matrix \(A\) in a column-major format.`beta`

(`double`

) – A scalar value that multiplies \(C\).`c`

(`double`

[]) – The pointer to the array storing matrix \(C\) in a column-major format.