[Tex/LaTex] \begin{align} not working when centering math equation

align

I've read a few posts here about center math equations and all of them make use of

\begin{align} *Math symbols* \end{align}

Now I've included the \usepackage{amsmath} before the begin document line. But I keep getting this error:

enter image description here

Any ideas guys? I'm a latex noob

Here is some code:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\section{Situation 1}

\begin{align}
$J_{(j)} = \sum\limits_{i:r(i,j)=1} ((\theta\textsuperscript{(j)})\textsuperscript{T}x\textsuperscript{(i)} - Y_{i,j})^2 + \frac{\lambda}{2}\sum\limits_{k=1}^n(\theta_k\textsuperscript{(j)})^2$
\end{align}

\end{document}

Best Answer

TeX is great for math typesetting; so it's unlikely that a formula like that is so complicated to input:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\section{Situation 1}

\begin{equation*}
J_{(j)} = 
  \sum_{i:r(i,j)=1} \bigl((\theta^{(j)})^{T} x^{(i)} - Y_{i,j}\bigr)^2 + 
  \frac{\lambda}{2}\sum_{k=1}^{n}\bigl(\theta_{k}^{(j)}\bigr)^2
\end{equation*}

\end{document}

There should never be \textsuperscript inside a formula.

Using \bigl and \bigr in the first formula makes the parentheses slightly bigger, which is good for reading in this case. Since they are almost necessary in the furst summation, I used them also in the second one, for symmetry.

enter image description here

The align environment is for multiline displays; if you want the equation numbered, then use equation instead of equation*.

But in any case, the contents of equation, align and similar environments is already assumed to be math, so adding $ will give errors.

Related Question