A high-performance general-purpose compute library

Solve a system of equations. More...

Functions

AFAPI array solve (const array &a, const array &b, const matProp options=AF_MAT_NONE)
 C++ Interface to solve a system of equations. More...
 
AFAPI af_err af_solve (af_array *x, const af_array a, const af_array b, const af_mat_prop options)
 C Interface to solve a system of equations. More...
 

Detailed Description

Solve a system of equations.

This function takes a co-efficient matrix \(A\) and an output matrix \(B\) as inputs to solve the following equation for \(X\), \(A * X = B\).

This operation can be done in ArrayFire using the following code snippet.

af::array X1 = af::solve(A, B0);
A multi dimensional data container.
Definition: array.h:37
AFAPI array solve(const array &a, const array &b, const matProp options=AF_MAT_NONE)
C++ Interface to solve a system of equations.

The results can be verified by reconstructing the output matrix using af::matmul in the following manner,

af::array B1 = af::matmul(A, X1);
AFAPI array matmul(const array &lhs, const array &rhs, const matProp optLhs=AF_MAT_NONE, const matProp optRhs=AF_MAT_NONE)
C++ Interface to multiply two matrices.

The sample output can be seen below.

A [3 3 1 1]
0.1000 3.1000 6.1000
1.1000 4.1000 7.0000
2.0000 5.0000 8.0000
B0 [3 1 1 1]
21.9000
30.7000
39.0000
X1 [3 1 1 1]
4.0000
3.0000
2.0000
B1 [3 1 1 1]
21.9000
30.7000
39.0000

If the coefficient matrix is known to be a triangular matrix, AF_MAT_LOWER or AF_MAT_UPPER can be passed to make solve faster.

The sample code snippets for solving a lower triangular matrix can be seen below.

@ AF_MAT_LOWER
Matrix is lower triangular.
Definition: defines.h:354

Similarily, the code snippet for solving an upper triangular matrix can be seen below.

@ AF_MAT_UPPER
Matrix is upper triangular.
Definition: defines.h:353

See also: af::solveLU


Function Documentation

◆ af_solve()

AFAPI af_err af_solve ( af_array x,
const af_array  a,
const af_array  b,
const af_mat_prop  options 
)

C Interface to solve a system of equations.

The options parameter must be one of AF_MAT_NONE, AF_MAT_LOWER or AF_MAT_UPPER.

This function is not supported in GFOR.

Parameters
[out]xmatrix of unknown variables
[in]acoefficient matrix
[in]bmeasured values
[in]optionsdetermines various properties of matrix a
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given

◆ solve()

AFAPI array solve ( const array a,
const array b,
const matProp  options = AF_MAT_NONE 
)

C++ Interface to solve a system of equations.

The options parameter must be one of AF_MAT_NONE, AF_MAT_LOWER or AF_MAT_UPPER.

This function is not supported in GFOR.

Parameters
[in]acoefficient matrix
[in]bmeasured values
[in]optionsdetermines various properties of matrix a
Returns
x, the matrix of unknown variables