libdspl-2.0
Digital Signal Processing Algorithm Library
|
Functions | |
int DSPL_API | matrix_eig_cmplx (complex_t *a, int n, complex_t *v, int *info) |
Eigenvalues calculation of the complex square matrix a . More... | |
int DSPL_API | matrix_eye (double *a, int n, int m) |
The real identity matrix size n x m generation. More... | |
int DSPL_API | matrix_eye_cmplx (complex_t *a, int n, int m) |
The complex identity matrix size n x m generation. More... | |
int DSPL_API | matrix_mul (double *a, int na, int ma, double *b, int nb, int mb, double *c) |
Matrix multiplication. More... | |
Detailed Description
This group describes the linear algebra algorithms and matrix operations. DSPL-2.0 using internal interface for BLAS and LAPACK packages.
Function Documentation
◆ matrix_eig_cmplx()
Eigenvalues calculation of the complex square matrix a
.
Function calculates n
eigenvalues of the matrix a
size n x n
.
- Parameters
-
[in] a Pointer to the complex matrix a
sizen x n
.
Matrix is stored in the memory as column-major array.
[in] n Size of matrix n x n
.
[out] v Pointer to the eigenvalues vector.
Vector size is]n x 1]
.
Memory must be allocated.
[out] info Pointer to the zgees
LAPACK subroutine output parameter.
If an error occurs while calculating the vector of eigenvalues, the LAPACK subroutine returns an error code that can be read from this pointer.
- Returns
RES_OK
— function is calculated successfully.
Else code error.
If anERROR_LAPACK
error occurs, the LAPACK package error code will be written to theinfo
address.
Eigenvalues calculation example:
This program calculates eigenvalues of the matrix size 3 x 3
and print its to display.
Result:
A = [ % size [3 x 3] type: complex 1.00 +0.00i, 2.00 +0.00i, 3.00 +0.00i; 1.00 +0.00i, 0.00 +0.00i, 0.00 +0.00i; 0.00 +0.00i, 1.00 +0.00i, 0.00 +0.00i;]; v = [ % size [3 x 1] type: complex 2.374424 -0.000000i; -0.687212 +0.889497i; -0.687212 -0.889497i;];
Definition at line 143 of file matrix_eig_cmplx.c.
Referenced by polyroots().
◆ matrix_eye()
int matrix_eye | ( | double * | a, |
int | n, | ||
int | m | ||
) |
The real identity matrix size n x m
generation.
Function fills matrix a
by zeros and sets main diagonal as ones.
- Parameters
-
[in] a Pointer to the real matrix size n x m
.
Matrix is stored in the memory as column-major array.
[in] n Matrix a
rows number.
[in] m Matrix a
columns number..
- Returns
RES_OK
— function is calculated successfully.
Else code error.
Definition at line 80 of file matrix_eye.c.
◆ matrix_eye_cmplx()
int matrix_eye_cmplx | ( | complex_t * | a, |
int | n, | ||
int | m | ||
) |
The complex identity matrix size n x m
generation.
Function fills matrix a
by zeros and sets main diagonal as ones.
- Parameters
-
[in] a Pointer to the complex matrix size n x m
.
Matrix is stored in the memory as column-major array.
[in] n Matrix a
rows number.
[in] m Matrix a
columns number..
- Returns
RES_OK
— function is calculated successfully.
Else code error.
Definition at line 81 of file matrix_eye_cmplx.c.
◆ matrix_mul()
int matrix_mul | ( | double * | a, |
int | na, | ||
int | ma, | ||
double * | b, | ||
int | nb, | ||
int | mb, | ||
double * | c | ||
) |
Matrix multiplication.
The function calculates the product of matrices \(\mathbf{C} = \mathbf{AB}\), here \(\mathbf{A}\) – matrix contains \(N_A\) rows and \(M_A\) columns, \(\mathbf{B}\) – matrix contains \(N_B\) rows and \(M_B\) columns, product matrix \(\mathbf{C} = \mathbf{AB}\) contains \(N_A\) rows and \(M_B\) columns.
- Note
- Matrix multiplication requires the equality \(M_A = N_B\).
Function uses BLAS subroutinedgemm
.
- Parameters
-
[in] a Pointer to the input matrix \(\mathbf{A}\) size na x ma
.
Matrix must be located in memory as column-major array.
[in] na Matrix a
rows number.
[in] ma Matrix a
columns number.
[in] b Pointer to the input matrix \(\mathbf{B}\) size nb x mb
.
Matrix must be located in memory as column-major array.
[in] nb Matrix b
rows number.
Necessary equalityma = nb
.
[in] mb Matrix a
columns number.
[out] c Pointer to the output matrix \(\mathbf{С} = \mathbf{AB}\).
Matrix size isna x mb
.
Memory must be allocated.
- Returns
RES_OK
— function is calculated successfully.
Else error code.
Example:#include <stdio.h>#include <stdlib.h>#include <string.h>#include "dspl.h"#define N 4#define M 3#define K 5int main(){void* handle; /* DSPL handle */handle = dspl_load(); /* Load DSPL function */double a[N*K], b[K*M], c[N*M];linspace(0, N*K, N*K, DSPL_PERIODIC, a);matrix_print(a, N, K, "A", "%8.2f");linspace(0, K*M, K*M, DSPL_PERIODIC, b);matrix_print(b, K, M, "B", "%8.2f");matrix_mul(a, N, K, b, K, M, c);matrix_print(c, N, M, "C", "%8.2f");dspl_free(handle); /* free dspl handle */return 0;}int DSPL_API linspace(double x0, double x1, int n, int type, double *x)Function fills a vector with n linearly spaced elements between x0 and x1.Definition: linspace.c:169int DSPL_API matrix_mul(double *a, int na, int ma, double *b, int nb, int mb, double *c)Matrix multiplication.Definition: matrix_mul.c:191
The program forms and multiplies two matrices. The original matrices and their product are printed.
The result of the program:
A = [ % size [4 x 5] type: real 0.00, 4.00, 8.00, 12.00, 16.00; 1.00, 5.00, 9.00, 13.00, 17.00; 2.00, 6.00, 10.00, 14.00, 18.00; 3.00, 7.00, 11.00, 15.00, 19.00;]; B = [ % size [5 x 3] type: real 0.00, 5.00, 10.00; 1.00, 6.00, 11.00; 2.00, 7.00, 12.00; 3.00, 8.00, 13.00; 4.00, 9.00, 14.00;]; C = [ % size [4 x 3] type: real 120.00, 320.00, 520.00; 130.00, 355.00, 580.00; 140.00, 390.00, 640.00; 150.00, 425.00, 700.00;];
Definition at line 191 of file matrix_mul.c.
Generated on Wed Jan 5 2022 12:44:37 for libdspl-2.0 by 1.9.2