# Error equation on multiple line

I'm trying to use the equation tag on the following portion of formula:

I did it as well:

\centerline{ \min _{w, b, \xi_{i}} \frac{\|w\|^{2}}{2}+C \sum_{i=1}^{n} \xi_{i} } subject to: \centerline{ \begin{aligned} y_{i}\left(w^{T} \phi\left(x_{i}\right)+b\right) \geq 1-\xi_{i} & & \text { for all } i=1, \ldots, n \\ \xi_{i} \geq 0 & & \text { for all } i=1, \ldots, n \end{aligned}}


but when I run it I get the following error:

1 - Missing $inserted. 2 - Display math should end with$\$.

3 - Bad math environment delimiter.

• Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Sep 28 at 13:16
• \centerline shouldn't really be used in latex and certainly not in or around equations. you can also not have blank lines in equations. Sep 28 at 13:17

Like this?:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{gather}
\min _{w, b, \xi_{i}} \frac{\|w\|^{2}}{2}+C \sum_{i=1}^{n} \xi_{i}
\shortintertext{subject to:}
\begin{aligned}
y_{i}\left(w^{T} \phi\left(x_{i}\right)+b\right) \geq 1-\xi_{i} & & \text { for all } i=1, \ldots, n \\
\xi_{i} \geq 0 & & \text { for all } i=1, \ldots, n
\end{aligned}
\end{gather}
\end{document}


Edit: As Sebastiano suggest in a comment this optimization problems should be written with optidef package:

\documentclass{article}
\usepackage{optidef}
\begin{document}
\begin{mini}
{w, b, \xi_{i}}{\frac{\|w\|^{2}}{2}+C \sum_{i=1}^{n} \xi_{i}}{}{}

• I will see optidef package, thanks for the suggestion! Sep 28 at 22:52
• Thank you for letting me know about optidef` package Sep 29 at 16:01