# TSSetRHSJacobian
Sets the function to compute the Jacobian of G, where U_t = G(U,t), as well as the location to store the matrix. 
## Synopsis
```
#include "petscts.h"  
PetscErrorCode TSSetRHSJacobian(TS ts, Mat Amat, Mat Pmat, TSRHSJacobian f, void *ctx)
```
Logically Collective


## Input Parameters

- ***ts  -*** the `TS` context obtained from `TSCreate()`
- ***Amat -*** (approximate) Jacobian matrix
- ***Pmat -*** matrix from which preconditioner is to be constructed (usually the same as Amat)
- ***f   -*** the Jacobian evaluation routine
- ***ctx -*** [optional] user-defined context for private data for the
Jacobian evaluation routine (may be NULL)



## Calling sequence of f
```none
PetscErrorCode f(TS ts,PetscReal t,Vec u,Mat A,Mat B,void *ctx);
```


- ***t -*** current timestep
- ***u -*** input vector
- ***Amat -*** (approximate) Jacobian matrix
- ***Pmat -*** matrix from which preconditioner is to be constructed (usually the same as Amat)
- ***ctx -*** [optional] user-defined context for matrix evaluation routine





## Notes
You must set all the diagonal entries of the matrices, if they are zero you must still set them with a zero value

The `TS` solver may modify the nonzero structure and the entries of the matrices Amat and Pmat between the calls to f()
You should not assume the values are the same in the next call to f() as you set them in the previous call.


## See Also
 [](chapter_ts), `TS`, `SNESComputeJacobianDefaultColor()`, `TSSetRHSFunction()`, `TSRHSJacobianSetReuse()`, `TSSetIJacobian()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/interface/ts.c.html#TSSetRHSJacobian">src/ts/interface/ts.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex1.c.html">src/ts/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex13.c.html">src/ts/tutorials/ex13.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex16fwd.c.html">src/ts/tutorials/ex16fwd.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex1f.F90.html">src/ts/tutorials/ex1f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex2.c.html">src/ts/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex20adj.c.html">src/ts/tutorials/ex20adj.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex20opt_ic.c.html">src/ts/tutorials/ex20opt_ic.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex20opt_p.c.html">src/ts/tutorials/ex20opt_p.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex20td.c.html">src/ts/tutorials/ex20td.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex21.c.html">src/ts/tutorials/ex21.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex3.c.html">src/ts/tutorials/ex3.c.html</A><BR>


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


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