使用分段函数的错误

使用分段函数的错误

我目前正在尝试用 LaTeX 写一份家庭作业,我需要创建一个分段函数来解决这个问题;但是,无论我怎么尝试,都会出现错误。我尝试了很多不同的解决方案,但都没有用。我将在下面给出几个例子和我尝试过的方法。另外,我确保在文档开头包含 \usepackage{amsmath}。

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

这个给了我'放错对齐制表符 &','放错 \crcr','额外 } 或忘记 \endgroup' 和 '缺少 \endgroup' 错误

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

与以前相同的错误

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

同样的错误

我将省去很多代码来说明我尝试了多少不同的事情。我尝试了几乎所有可以想象到的组合,将某些部分(主要是所有文本)从数学模式中取出,将某些部分插入数学模式中,但都不起作用。我很感激任何帮助和/或建议

编辑:这是整个文档。我仍然收到相同的错误

\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}

我编译的问题的图片

答案1

文件

\documentclass{article}

\begin{document}

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

产生错误

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

请注意,它准确地显示了检测到错误的位置,而您的摘要并未显示。

如果你加载它amsmath,它就会运行而不会出现错误:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

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

在此处输入图片描述

答案2

\textbf不能包含段落分隔符,因此最好使用 来设置粗体段落{\bfseries ...}。此外,\therefore源于amssymb你没有包括它。

在此处输入图片描述

\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}

相关内容