# Errors using piecewise function [closed]

I am currently attempting to write a homework assignment in LaTeX and I need to create a piecewise function in order to solve the problem; however, no matter what I try, I am given errors. I have attempted a lot of different solution but nothing is working. I will give a few examples below and what I have attempted. Also, I have made sure to include \usepackage{amsmath} in the beginning of my document.

$h(x) = \begin{cases} {2x} - 3 & x\leq 3 \\ 3 & x > 3 \end{cases}$


This one gives me 'misplaced alignment tab character &', 'misplaced \crcr', 'Extra }, or forgotten \endgroup', and 'missing \endgroup' errors

$h(x) = \begin{cases} {2x} - 3 & x\leq 3 \\ 3 & x > 3 \end{cases}$


Same errors as before

$$h(x) = \begin{cases} {2x} - 3 & x\leq 3 \\ 3 & x > 3 \end{cases}$$


Same errors

I am going to spare you guys a lot more code illustrating how many different things I have attempted. I have tried pretty much every imaginable combination of taking certain sections (mainly all the text) out of math mode and inserting certain sections in math mode but nothing is working. I appreciate any help and/or advice

EDIT: Here is the entirety of the document. I am still receiving the same errors

\documentclass{article}
\usepackage{mathtools}
\usepackage{amsmath}

\begin{document}

\textbf{A beverage stand orders a certain number of a particular soda each day. Let X be a random variable defined as the number of sodas demanded on each day with the following probabilities: \\
Suppose each soda costs \$1.00 and the customer pays \$2.00 for each. The sodas go flat at the end of the day so the owner must throw out unsold sodas. Is it better for the owner to order three or four sodas each day?

Let h $_{1}$(x) represent the net revenue for 3 sodas sold. (If the demand exceeds 3, the number of sodas sold is simply equal to three). \\
$\therefore$ the revenue function as a function of demand for 3 sodas can be written as such: \\

$h(x) = \begin{cases} {2x} - 3 & x\leq 3 \\ 3 & x > 3 \end{cases}$

\end{document}


• welcome to tex.se! all your example works without any error. so, please, extend one of your example to complete small document (mwe: minimal working example) starting with \documentclass{...}, necessary preamble, as document body one of your example and ending with \end{document} which will reproduce your error(s). – Zarko Apr 10 '19 at 23:42
• as well as showing a small complete test document, you should show the full error message from the log file in a code block. The format of the error that you show is not the format tex uses which would show which & was causing an error. – David Carlisle Apr 10 '19 at 23:55
• @DavidCarlisle I updated my post to include a test document and image of my compiled document. I am still having issues with the first & and the \end{cases} statement – macaato Apr 11 '19 at 0:31
• @Zarko I have included the information you requested – macaato Apr 11 '19 at 0:31
• The document posted has a completely unrelated error ! File ended while scanning use of \textbf as you have no closing } for the bold text. – David Carlisle Apr 11 '19 at 7:28

The document

\documentclass{article}

\begin{document}

$h(x) = \begin{cases} {2x} - 3 & x\leq 3 \\ 3 & x > 3 \end{cases}$
\end{document}


Produces the error

! Misplaced alignment tab character &.
l.8     {2x} - 3 &
x\leq 3 \\
?


Note that it shows exactly the point at which the error is detected, which your summary did not show.

If you load amsmath then it runs without error:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

$h(x) = \begin{cases} {2x} - 3 & x\leq 3 \\ 3 & x > 3 \end{cases}$
\end{document}


• in question OP claims, that he/she use amsmath :-) – Zarko Apr 11 '19 at 0:11
• – David Carlisle Apr 11 '19 at 7:31
• you are right! next time will more suspicious about OP claims :-) – Zarko Apr 11 '19 at 10:19

\textbf cannot include paragraph breaks, so it's better to set bold paragraphs using {\bfseries ...}. Also, \therefore stems from amssymb which you didn't include.

\documentclass{article}

\usepackage{amsmath,amssymb}

\begin{document}

{\bfseries A beverage stand orders a certain number of a particular soda each day. Let X be a random variable defined as the number of sodas demanded on each day with the following probabilities:
Suppose each soda costs \$1.00 and the customer pays \$2.00 for each. The sodas go flat at the end of the day so the owner must throw out unsold sodas. Is it better for the owner to order three or four sodas each day?}

Let $h_1(x)$ represent the net revenue for 3 sodas sold. (If the demand exceeds 3, the number of sodas sold is simply equal to three).

$\therefore$ the revenue function as a function of demand for 3 sodas can be written as such:
$h(x) = \begin{cases} 2x - 3 & x \leq 3 \\ 3 & x > 3 \end{cases}$

\end{document}

• This is all good to know, but none if it solved my issues – macaato Apr 11 '19 at 0:51
• @macaato: Can you post your . log when you compile the minimal example you gave? – Werner Apr 11 '19 at 1:10
• I solved my issue. Turns out there was another package I was using that was causing the issues. Thank you for your input – macaato Apr 11 '19 at 1:22