# TaoSetResidualRoutine
Sets the residual evaluation routine for least-square applications 
## Synopsis
```
#include "petsctao.h" 
PetscErrorCode TaoSetResidualRoutine(Tao tao, Vec res, PetscErrorCode (*func)(Tao, Vec, Vec, void *), void *ctx)
```
Logically collective on tao


## Input Parameters

- ***tao -*** the Tao context
- ***func -*** the residual evaluation routine
- ***ctx -*** [optional] user-defined context for private data for the function evaluation
routine (may be NULL)



## Calling sequence of func
```none
func (Tao tao, Vec x, Vec f, void *ctx);
```


- ***x -*** input vector
- ***f -*** function value vector
- ***ctx -*** [optional] user-defined function context





## See Also
 `Tao`, `TaoSetObjective()`, `TaoSetJacobianRoutine()`

## Level
beginner

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/leastsquares/tutorials/chwirut1.c.html">src/tao/leastsquares/tutorials/chwirut1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/leastsquares/tutorials/chwirut1f.F90.html">src/tao/leastsquares/tutorials/chwirut1f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/leastsquares/tutorials/chwirut2.c.html">src/tao/leastsquares/tutorials/chwirut2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/leastsquares/tutorials/chwirut2f.F90.html">src/tao/leastsquares/tutorials/chwirut2f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/leastsquares/tutorials/cs1.c.html">src/tao/leastsquares/tutorials/cs1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/leastsquares/tutorials/tomography.c.html">src/tao/leastsquares/tutorials/tomography.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)  
