1

Escaping "^" after \tt is causing formatting error in the following code. All words after \^{} is being affected by \tt.

Code:

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

Current output:

enter image description here

Is there a way to resolve this issue?

ferris
  • 149

1 Answers1

3

Your code works file for me. However,

  1. you should not use the deprecated \tt. Such commands are some of the most deprecated commands in LaTeX.

  2. \verb is for that purpose. You can use something as simple as \verb|a^b| to get a^b instead of \texttt{a\^{}b}; or \verb|\cmd| to get \cmd instead of \texttt{\textbackslash{}cmd}.

Code:

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

enter image description here