:orphan:
# TSSetCostHessianProducts
Sets the initial value of the Hessian-vector products of the cost function w.r.t. initial values and w.r.t. the problem parameters for use by the `TS` adjoint routines. 
## Synopsis
```
#include "petscts.h"  
PetscErrorCode TSSetCostHessianProducts(TS ts, PetscInt numcost, Vec *lambda2, Vec *mu2, Vec dir)
```
Logically Collective


## Input Parameters

- ***ts -*** the `TS` context obtained from `TSCreate()`
- ***numcost -*** number of cost functions
- ***lambda2 -*** Hessian-vector product with respect to the initial condition variables, the dimension and parallel layout of these vectors is the same as the ODE solution vector
- ***mu2 -*** Hessian-vector product with respect to the parameters, the number of entries in these vectors is the same as the number of parameters
- ***dir -*** the direction vector that are multiplied with the Hessian of the cost functions





## Notes
Hessian of the cost function is completely different from Hessian of the ODE/DAE system

For second-order adjoint, one needs to call this function and then `TSAdjointSetForward()` before `TSSolve()`.

After `TSAdjointSolve()` is called, the lambda2 and the mu2 will contain the computed second-order adjoint sensitivities, and can be used to produce Hessian-vector product (not the full Hessian matrix). Users must provide a direction vector; it is usually generated by an optimization solver.

Passing `NULL` for `lambda2` disables the second-order calculation.


## See Also
 [](ch_ts), `TS`, `TSAdjointSolve()`, `TSAdjointSetForward()`

## Level
beginner

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex20opt_ic.c.html">src/ts/tutorials/ex20opt_ic.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex20opt_p.c.html">src/ts/tutorials/ex20opt_p.c</A><BR>


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


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