# TaoSetJacobianResidualRoutine
Sets the function to compute the least-squares residual Jacobian as well as the location to store the matrix. 
## Synopsis
```
#include "petsctao.h" 
PetscErrorCode TaoSetJacobianResidualRoutine(Tao tao, Mat J, Mat Jpre, PetscErrorCode (*func)(Tao, Vec, Mat, Mat, void *), void *ctx)
```
Logically collective on tao


## Input Parameters

- ***tao  -*** the Tao context
- ***J    -*** Matrix used for the jacobian
- ***Jpre -*** Matrix that will be used operated on by preconditioner, can be same as J
- ***func -*** Jacobian evaluation routine
- ***ctx  -*** [optional] user-defined context for private data for the
Jacobian evaluation routine (may be NULL)



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


- ***tao  -*** the Tao  context
- ***x    -*** input vector
- ***J    -*** Jacobian matrix
- ***Jpre -*** preconditioning matrix, usually the same as J
- ***ctx  -*** [optional] user-defined Jacobian context





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

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/interface/taosolver_hj.c.html#TaoSetJacobianResidualRoutine">src/tao/interface/taosolver_hj.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/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_hj.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)  
