<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/SparseSolve(_:_:)-60ngw",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@SparseSolve#$@SA@SparseOpaqueFactorization_Float#$@SA@DenseVector_Float#"
  },
  "title" : "SparseSolve(_:_:)"
}
-->

# SparseSolve(_:_:)

Solves the system *Ax = b* using the supplied single-precision factorization of *A*, in place.

```
func SparseSolve(_ Factored: SparseOpaqueFactorization_Float, _ xb: DenseVector_Float)
```

## Parameters

`Factored`

The factored matrix to solve.

`xb`

On input, the vector *b*. On return, the function overwrites with the vector *x*. If *A* has dimension *m x n*, this parameter must have length *k*, where *k = max(m,n)*.

## Discussion

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

![A mathematical equation that has one set of three simultaneous equations on the left. Each equation has three unknowns. The same set of simultaneous equations appears on the right as a single matrix equation, A x equals B. The single matrix equation consists of a three-by-three matrix multiplied by a three-element column matrix that equals a three-element column matrix.](images/com.apple.accelerate/media-3703891@2x.png)

The following code solves this system with a QR factorization of the coefficient matrix:

```objc
// Create the coefficient matrix `A` from coordinate (COO) arrays.
int rowIndices[]    = {0, 1, 1, 2};
int columnIndices[] = {2, 0, 2, 1};
float aValues[]     = {10, 20, 5, 50};

SparseMatrix_Float A = SparseConvertFromCoordinate(3, 3,
                                                   4, 1,
                                                   (SparseAttributes_t){0},
                                                   rowIndices, columnIndices,
                                                   aValues);

// Compute the factors of `A` using a QR decomposition.
SparseOpaqueFactorization_Float factorization = SparseFactor(SparseFactorizationQR, A);

// Create the right-hand-side vector `b` (also holds the solution on return).
float bValues[] = {30, 35, 100};

DenseVector_Float xb = {
    .count = 3,
    .data  = bValues
};

// Solve `Ax = b` in place.
SparseSolve(factorization, xb);

// Prints "[1, 2, 3]".
printf("[%g, %g, %g]\n", bValues[0], bValues[1], bValues[2]);

SparseCleanup(A);
SparseCleanup(factorization);
```

On return, `bValues` contains the values `[1.0, 2.0, 3.0]`.

If the factorization is *A = QR*, the function returns the solution of minimum norm *‖ x ‖₂* for underdetermined systems.

If the factorization is *A = QR*, the function returns the least squares solution *minₓ ‖ AX - B ‖₂* for overdetermined systems.

If the factorization is [`SparseFactorizationCholeskyAtA`](/documentation/Accelerate/SparseFactorizationCholeskyAtA), the factorization is of *AᵀA*, and the solution that returns is for the system *AᵀAX = B*.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)