# TSSetRHSFunction
Sets the routine for evaluating the function, where U_t = G(t,u). 
## Synopsis
```
#include "petscts.h"  
PetscErrorCode TSSetRHSFunction(TS ts, Vec r, PetscErrorCode (*f)(TS, PetscReal, Vec, Vec, void *), void *ctx)
```
Logically Collective


## Input Parameters

- ***ts -*** the `TS` context obtained from `TSCreate()`
- ***r -*** vector to put the computed right hand side (or NULL to have it created)
- ***f -*** routine for evaluating the right-hand-side function
- ***ctx -*** [optional] user-defined context for private data for the
function evaluation routine (may be NULL)



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


- ***ts -*** timestep context
- ***t -*** current timestep
- ***u -*** input vector
- ***F -*** function vector
- ***ctx -*** [optional] user-defined function context





## Note
You must call this function or `TSSetIFunction()` to define your ODE. You cannot use this function when solving a DAE.


## See Also
 [](chapter_ts), `TS`, `TSSetRHSJacobian()`, `TSSetIJacobian()`, `TSSetIFunction()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/interface/ts.c.html#TSSetRHSFunction">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/ex12.c.html">src/ts/tutorials/ex12.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/ex16.c.html">src/ts/tutorials/ex16.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/ex20.c.html">src/ts/tutorials/ex20.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>


---
[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)  
