Solve a system of equations. More...

Functions

AFAPI array solve (const array &a, const array &b, const matProp options=AF_MAT_NONE)
 C++ Interface for solving 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 for solving 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);

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

af::array B1 = af::matmul(A, X1);

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.

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

See also: af::solveLU


Function Documentation

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

C Interface for solving a system of equations.

Parameters
[out]xis the matrix of unknown variables
[in]ais the coefficient matrix
[in]bis the measured values
[in]optionsdetermining various properties of matrix a
Note
options needs to be one of AF_MAT_NONE, AF_MAT_LOWER or AF_MAT_UPPER
AFAPI array af::solve ( const array a,
const array b,
const matProp  options = AF_MAT_NONE 
)

C++ Interface for solving a system of equations.

Parameters
[in]ais the coefficient matrix
[in]bis the measured values
[in]optionsdetermining various properties of matrix a
Returns
x, the matrix of unknown variables
Note
options needs to be one of AF_MAT_NONE, AF_MAT_LOWER or AF_MAT_UPPER
This function is not supported in GFOR