# Maximizing an Objective

All solvers attempt to minimize an objective function. If you have a maximization problem, that is, a problem of the form

$\underset{x}{\mathrm{max}}f\left(x\right)$,

then define and minimize $g$.

For example, to find the maximum of $\mathrm{tan}\left(\mathrm{cos}\left(x\right)\right)$ near , evaluate

`[x,fval] = fminunc(@(x)-tan(cos(x)),5)`
```Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance. ```
```x = 6.2832 ```
```fval = -1.5574 ```

The maximum is `1.5574` (the negative of the reported `fval`), and occurs at `x = 6.2832`. This answer is correct because, to five digits, the maximum is , which occurs at .