转义后面的“^”\tt
会导致以下代码出现格式错误。后面的所有单词\^{}
都会受到影响\tt
。
代码:
\item Use the {\tt linspace} command to create a vector $\mathbf{x} \in \mathbb{R}^{100}$ containing 100 equally spaced points between 0 and 10 (inclusive). Use this vector to create the Vandermonde matrix $\mathbf{D} \in \mathbb{R}^{100 \times 4}$ with rows $\begin{bmatrix} 1 & x_i & x_i^2 & x_i^3 \end{bmatrix}$ for $i = 1,\dots,100$. (Hint: While using {\tt x\^{}n} will result in an error, using {\tt x.\^{}n} will return a vector where each element is raised to the $n$th power.) Save the matrix $\mathbf{D}$ as {\tt A4.dat}.
电流输出:
有办法解决这个问题吗?
答案1
你的代码对我来说是有效的。然而,
你不应该使用已弃用的
\tt
. 此类命令是 LaTeX 中最不推荐使用的命令之一。\verb
就是为了这个目的。你可以使用一些简单的方法,比如\verb|a^b|
用 geta^b
代替\texttt{a\^{}b}
;或者\verb|\cmd|
用 get\cmd
代替\texttt{\textbackslash{}cmd}
。
代码:
\documentclass{article}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage[shortlabels]{enumitem}
\begin{document}
\begin{enumerate}[(a)]
\item Use the \verb|linspace| command to create a vector $\mathbf{x}
\in \mathbb{R}^{100}$ containing 100 equally spaced points between 0
and 10 (inclusive). Use this vector to create the Vandermonde matrix
$\mathbf{D} \in \mathbb{R}^{100 \times 4}$ with rows $\begin{bmatrix}
1 & x_i & x_i^2 & x_i^3 \end{bmatrix}$ for $i = 1,\dots,100$. (Hint:
While using \verb|x^n| will result in an error, using \verb|x.^n| will
return a vector where each element is raised to the $n$-th power.)
Save the matrix $\mathbf{D}$ as \verb|A4.dat|.
\end{enumerate}
\end{document}