# SNESSetObjective
Sets the objective function minimized by some of the `SNES` linesearch methods. 
## Synopsis
```
PetscErrorCode SNESSetObjective(SNES snes, PetscErrorCode (*obj)(SNES, Vec, PetscReal *, void *), void *ctx)
```
Logically Collective on snes


## Input Parameters

- ***snes -*** the `SNES` context
- ***obj -*** objective evaluation routine; see `SNESObjectiveFunction` for details
- ***ctx -*** [optional] user-defined context for private data for the
function evaluation routine (may be NULL)





## Note
Some of the `SNESLineSearch` methods attempt to minimize a given objective provided by this function to determine a step length.

If not provided then this defaults to the two norm of the function evaluation (set with `SNESSetFunction()`)

This is not used in the `SNESLINESEARCHCP` line search.


## See Also
 `SNES`, `SNESLineSearch()`, `SNESGetObjective()`, `SNESComputeObjective()`, `SNESSetFunction()`, `SNESSetJacobian()`, `SNESObjectiveFunction`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/interface/snesob.c.html#SNESSetObjective">src/snes/interface/snesob.c</A>


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


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