# Maximize a function (maximize)

The maximum of an expression and the point where it is reached.

## How to write it

### maximize(expr, variables)

The greatest value over every real value of the variables.

**expr**

Any expression: a number, a formula, a list or a matrix. Takes an expression.

**variables**

A variable, or a list of variables such as \[x, y\]. Takes a variable, or a list of variables.

### maximize(expr, variables)

Under conditions, over whole unknowns too, and with the least of several linear pieces.

**expr**

The objective first, then its conditions, in brackets. Takes a list.

**variables**

A variable, or a list of variables such as \[x, y\]. Takes a variable, or a list of variables.

## Examples

- $\displaystyle \max_{x} (-x^{2}+2 x) = \left[ 1, \left[ x \to 1 \right] \right]$

  `maximize(-x^2 + 2x, x)`

  In the solver, `maximize(-x^2 + 2x, x)` gives `[1, [x -> 1]]`.

  [Open in the solver](https://hilberon.com/?q=maximize%28-x%5E2%20%2B%202x%2C%20x%29)
- $\displaystyle \max_{x, y} \left[ 5 x+4 y, 6 x+4 y \le 24, x+2 y \le 6, x \ge 0, y \ge 0, \left[ x, y \right] \in \mathbb{Z} \right] = \left[ 20, \left[ x \to 4, y \to 0 \right] \right]$

  `maximize([5x + 4y, 6x + 4y <= 24, x + 2y <= 6, x >= 0, y >= 0, [x, y] : integer], [x, y])`

  In the solver, `maximize([5x + 4y, 6x + 4y <= 24, x + 2y <= 6, x >= 0, y >= 0, [x, y] : integer], [x, y])` gives `[20, [x -> 4, y -> 0]]`.

  [Open in the solver](https://hilberon.com/?q=maximize%28%5B5x%20%2B%204y%2C%206x%20%2B%204y%20%3C%3D%2024%2C%20x%20%2B%202y%20%3C%3D%206%2C%20x%20%3E%3D%200%2C%20y%20%3E%3D%200%2C%20%5Bx%2C%20y%5D%20%3A%20integer%5D%2C%20%5Bx%2C%20y%5D%29)
- $\displaystyle \max_{x, y} \left[ \min(x, y, 6-x-y), x \ge 0, y \ge 0 \right] = \left[ 2, \left[ x \to 2, y \to 2 \right] \right]$

  `maximize([min(x, y, 6 - x - y), x >= 0, y >= 0], [x, y])`

  In the solver, `maximize([min(x, y, 6 - x - y), x >= 0, y >= 0], [x, y])` gives `[2, [x -> 2, y -> 2]]`.

  [Open in the solver](https://hilberon.com/?q=maximize%28%5Bmin%28x%2C%20y%2C%206%20-%20x%20-%20y%29%2C%20x%20%3E%3D%200%2C%20y%20%3E%3D%200%5D%2C%20%5Bx%2C%20y%5D%29)
- $\displaystyle \max_{x, y} \left[ x^{2}+y^{2}, x+2 y \le 8, 3 x+y \le 9, x \ge 0, y \ge 0, \left[ x, y \right] \in \mathbb{Z} \right] = \left[ 16, \left[ x \to 0, y \to 4 \right] \right]$

  `maximize([x^2 + y^2, x + 2y <= 8, 3x + y <= 9, x >= 0, y >= 0, [x, y] : integer], [x, y])`

  In the solver, `maximize([x^2 + y^2, x + 2y <= 8, 3x + y <= 9, x >= 0, y >= 0, [x, y] : integer], [x, y])` gives `[16, [x -> 0, y -> 4]]`.

  [Open in the solver](https://hilberon.com/?q=maximize%28%5Bx%5E2%20%2B%20y%5E2%2C%20x%20%2B%202y%20%3C%3D%208%2C%203x%20%2B%20y%20%3C%3D%209%2C%20x%20%3E%3D%200%2C%20y%20%3E%3D%200%2C%20%5Bx%2C%20y%5D%20%3A%20integer%5D%2C%20%5Bx%2C%20y%5D%29)
- $\displaystyle \max_{x, y, z} \left[ x y z, x+y+z = 3, x > 0, y > 0, z > 0 \right] = \left[ 1, \left[ x \to 1, y \to 1, z \to 1 \right] \right]$

  `maximize([x*y*z, x + y + z = 3, x > 0, y > 0, z > 0], [x, y, z])`

  In the solver, `maximize([x*y*z, x + y + z = 3, x > 0, y > 0, z > 0], [x, y, z])` gives `[1, [x -> 1, y -> 1, z -> 1]]`.

  [Open in the solver](https://hilberon.com/?q=maximize%28%5Bx*y*z%2C%20x%20%2B%20y%20%2B%20z%20%3D%203%2C%20x%20%3E%200%2C%20y%20%3E%200%2C%20z%20%3E%200%5D%2C%20%5Bx%2C%20y%2C%20z%5D%29)

## Functions its examples use

- [min](https://hilberon.com/library/min)

  The smallest of some numbers.

## Related functions

- [numeric_maximize](https://hilberon.com/library/numeric_maximize)

  The maximum of an expression found numerically, with the point where it is reached.
- [min_value](https://hilberon.com/library/min_value)

  The minimum value of an expression.
- [max_value](https://hilberon.com/library/max_value)

  The maximum value of an expression.
- [minimize](https://hilberon.com/library/minimize)

  The minimum of an expression and the point where it is reached.
- [numeric_minimize](https://hilberon.com/library/numeric_minimize)

  The minimum of an expression found numerically, with the point where it is reached.

---
Source: https://hilberon.com/library/maximize
