---
title: "SparseSolve(_:_:_:_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/sparsesolve(_:_:_:_:)-1f00y"
---

# SparseSolve(_:_:_:_:)

Solves the equation AX = B for matrices of single-precision values using the specified iterative method.

## Declaration

```swift
func SparseSolve(_ method: SparseIterativeMethod, _ A: SparseMatrix_Float, _ B: DenseMatrix_Float, _ X: DenseMatrix_Float) -> SparseIterativeStatus_t
```

## Parameters

- `method`: The iterative method.
- `A`: The matrix A.
- `B`: The matrix B.
- `X`: The matrix X.

## Return Value

Return Value A SparseIterativeStatus_t enumeration that represents the status of the iterative solve.

## Discussion

Discussion Use this function to solve a system of linear equations using a factored coefficient matrix. The following figure shows two systems of equations where the coefficient matrix is sparse:

The following code solves this system using the least squares minimum residual method: /// Create the coefficient matrix _A_. let rowIndices: [Int32] =    [ 0,  1, 1,  2] let columnIndices: [Int32] = [ 2,  0, 2,  1] let aValues: [Float] =       [10, 20, 5, 50]

let A = SparseConvertFromCoordinate(3, 3,                                     4, 1,                                     SparseAttributes_t(),                                     rowIndices, columnIndices,                                     aValues)

defer {     SparseCleanup(A) }

/// Create the right-hand-side matrix, _B_. var bValues: [Float] = [30, 35, 100,                         300, 350, 1000] let n = bValues.count

let xValues = [Float](unsafeUninitializedCapacity: n) {     buffer, count in     bValues.withUnsafeMutableBufferPointer { bPtr in         let B = DenseMatrix_Float(rowCount: 3,                                   columnCount: 2,                                   columnStride: 3,                                   attributes: SparseAttributes_t(),                                   data: bPtr.baseAddress!)                  let X = DenseMatrix_Float(rowCount: 3,                                   columnCount: 2,                                   columnStride: 3,                                   attributes: SparseAttributes_t(),                                   data: buffer.baseAddress!)                  SparseSolve(SparseLSMR(),                     A, B, X)                  count = n     } } On return, xValues contains the values [1.0, 2.0, 3.0, 10.0, 20.0, 30.0].

## See Also

### Iterative sparse solve functions

- [SparseSolve(_:_:_:_:)](accelerate/sparsesolve(_:_:_:_:)-3ft19.md)
- [SparseSolve(_:_:_:_:)](accelerate/sparsesolve(_:_:_:_:)-vewd.md)
- [SparseSolve(_:_:_:_:)](accelerate/sparsesolve(_:_:_:_:)-8mtxu.md)
