“Missing { inserted” in align* environment

I have this bit of code:

\begin{align*}
P(\omega_{k}|x) \approx \hat{y_k}(x) = \frac{exp(w^{T}_{k}x^')}{\sum^{q}_{j=1}exp(w^{T}_{j}x^')}
\\
\end{align*}


That keeps sending me the following error message:

"! Missing { inserted. ^ l.295 \end{align*} A left brace was mandatory here, so I've put one in. You might want to delete and/or insert some corrections so that I will find a matching right brace soon. (If you're confused by all this, try typing I}' now.)"

I have no idea of to fix this as I am a new user of LaTeX... Could someone please help me? Thanks

• It is x', not x^'. But your coding should be thoroughly revised… – GuM May 1 '16 at 11:50
• Welcome, a compilable example is always best to show. You are citing an error in line 295, but you are showing us just five lines. Additionally, make use of package mathtools and its \text facility. => \text{and}, \exp. Additionally, you are not using any alignment separators (&), why using align then? – Johannes_B May 1 '16 at 11:51
• Thanks for the comments. As I said, I am new to LaTeX (and coding), so obviously there might be easier ways to obtain the results I am trying to achieve... I am trying to get better though. Thanks for the help. – Quinten May 1 '16 at 12:02

OK, @Johannes_B has already given you some advice. Meanwhile, I was trying to to tidy up your code: see if I have guessed your intentions correctly.

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.

\usepackage[ascii]{inputenc}     % Just to check that the source is still pure,
% 7-bit-clean ASCII when you execute it, as it
% was when I wrote it.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{mathtools}

\begin{document}

Text before.
\begin{gather*}
P(\omega_{k}|x) \approx \widehat{y_k}(x)
= \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')}  \\[\jot]
\text{where} \quad x' = [1, x_1, x_2,\dots,x_p]^T  \\
\text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{gather*}
Text after.

\end{document}


Anyway, I’d use a different approach, separating the part after “where” in another equation.

Addendum: Another possibility, using the split environment. Note also the introduction of a higher level of abstraction, by means of the \innerprod command.

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.

\usepackage[ascii]{inputenc}     % Just to check that the source is still pure,
% 7-bit-clean ASCII when you execute it, as it
% was when I wrote it.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{mathtools}

\DeclarePairedDelimiterX{\innerprod}[2]{(}{)}{%
#1\nonscript\medspace\delimsize\vert\nonscript\medspace\mathopen{}#2%
}

\begin{document}

Text before.
\begin{gather*}
\begin{split}
P\innerprod{\omega_{k}}{x} \approx \widehat{y_k}(x)
= \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')}
&\text{where} \quad x' = [1, x_1, x_2,\dots,x_p]^T  \\
&\text{with} \quad 0 \leq \widehat{y_k}(x) \leq 1  \\
&\text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{split}
\end{gather*}
Text after.

A few examples of the use of \verb|\innerprod|:
\begin{align*}
(a\mid b) &&
\innerprod{a}{b} &&
\innerprod[\Bigg]{a}{b} &&
\innerprod*{\frac{a}{b}}{\frac{c}{d}}
\end{align*}

\end{document}


This is the output:

• A small detail: I'd also replace | with \mid . – Mico May 1 '16 at 12:05
• This is exactly what I needed, thank you so much Gustavo! – Quinten May 1 '16 at 12:10
• @Mico: You’re right, I didn’t pay attention. But still better would be to use mathtools \DeclarePairedDelimiterX. – GuM May 1 '16 at 12:13

I propose one of these solutions, with the alignat environment:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\begin{document}

\begin{alignat*}{2}
P(\omega_{k}|x) & \approx \widehat{y_k}(x) & & = \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')}
\\[1ex]
& \text{where} & & \, x' = [1, x₁, x₂,...,x_p]^T \\[-1ex]
& \text{with} & & \, 0 \leq \widehat{y_k}(x) \leq 1 \quad \text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{alignat*}
\vskip1cm
\begin{alignat*}{2}
& & & P(\omega_{k}|x) \approx \widehat{y_k}(x) = \frac{\exp(w^{T}_{k}x')}{\sum^{q}_{j=1}\exp(w^{T}_{j}x')}
\\[1ex]
& \text{where}\quad & & x' = [1, x₁, x₂,...,x_p]^T \\[-1ex]
& \text{with} & & 0 \leq \widehat{y_k}(x) \leq 1 \quad \text{and} \quad \sum^{q}_{k=1} \widehat{y_k}(x) = 1
\end{alignat*}

\end{document}
`