---
title: "SparseConjugateGradient(_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/sparseconjugategradient(_:)"
---

# SparseConjugateGradient(_:)

Returns a conjugate gradient (CG) method with specified options.

## Declaration

```swift
func SparseConjugateGradient(_ options: SparseCGOptions) -> SparseIterativeMethod
```

## Parameters

- `options`: The options to use when creating the conjugate gradient method, such as the maximum number of iterations to perform.

## Return Value

Return Value A SparseIterativeMethod structure that represents a default conjugate gradient method.

## Discussion

Discussion Use CG to solve Ax = b when A is symmetric positive-definite. The method may break down or fail to converge if A isn’t positive-definite. For square, full-rank, unsymmetric or indefinite equations, use SparseGMRES(_:). For rectangular or singular systems, use SparseLSMR(_:).

## See Also

### Sparse Iterative Methods for Symmetric Positive-Definite Coefficient Matrices

- [SparseConjugateGradient()](accelerate/sparseconjugategradient().md)
- [SparseCGOptions](accelerate/sparsecgoptions.md)
