# TaoComputeGradient
Computes the gradient of the objective function 
## Synopsis
```
#include "petsctao.h" 
PetscErrorCode TaoComputeGradient(Tao tao, Vec X, Vec G)
```
Collective


## Input Parameters

- ***tao -*** the Tao context
- ***X -*** input vector



## Output Parameter

- ***G -*** gradient vector



## Options Database Keys

- ***-tao_test_gradient -*** compare the user provided gradient with one compute via finite differences to check for errors
- ***-tao_test_gradient_view -*** display the user provided gradient, the finite difference gradient and the difference between them to help users detect the location of errors in the user provided gradient



## Note
`TaoComputeGradient()` is typically used within the implementation of the optimization method,
so most users would not generally call this routine themselves.




## See Also
 `TaoComputeObjective()`, `TaoComputeObjectiveAndGradient()`, `TaoSetGradient()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/interface/taosolver_fg.c.html#TaoComputeGradient">src/tao/interface/taosolver_fg.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/tutorials/ex4.c.html">src/tao/tutorials/ex4.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/tao/interface/taosolver_fg.c)


[Index of all Tao routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
