0

I'm trying to use the equation tag on the following portion of formula: enter image description here

I did it as well:

\begin{equation}
\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}$}
\end{equation}

but when I run it I get the following error:

1 - Missing $ inserted.

2 - Display math should end with $$.

3 - Bad math environment delimiter.

2
  • 1
    Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Sep 28 at 13:16
  • 3
    `\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
5

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}

enter image description here


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}}{}{}
\addConstraint{y_{i}\left(w^{T} \phi\left(x_{i}\right)+b\right)}{\geq 1-\xi_{i}\quad}{\text {for all } i=1, \ldots, n}
\addConstraint{\xi_{i}}{\geq 0}{\text {for all } i=1, \ldots, n}
\end{mini}
\end{document}

enter image description here

The package has many environments and many alternatives to display this optimization problem. It also has some aligning points, that I have used in the example

4
  • 1
    +1 surely. I think that the optidef package It seems Better.
    – Sebastiano
    Sep 28 at 22:13
  • 1
    I will see optidef package, thanks for the suggestion! Sep 28 at 22:52
  • Very very good. It Is very nice. I had upvoted Yesterday.
    – Sebastiano
    Sep 29 at 14:23
  • 1
    Thank you for letting me know about optidef package Sep 29 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.