How do I create a Toeplitz matrix like the following in LaTeX?
[Tex/LaTex] Toeplitz matrix in LaTeX
matrices
Related Solutions
I am not sure that is good enough for you, but one way to display this matris is to:
- Define symbols for expressions that occur often.
- Even with #1, this still required scaling the matrix to fit in the line width
Another solution is to define a symbol for the four complicated entries:
Notes:
- The
[showframe]
option was applied to thegeometry
package just to show the page margins. - Numerous
\,
were eliminated -- They are not necessary as the spacing is correct without them.
Code:
\documentclass[12pt]{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{mathtools}
\usepackage{graphicx}
\newcommand{\SQ}{\phi}
\newcommand{\SQExpanded}{x^{2} + y^{2}}
\newcommand{\FivePi}{\omega}
\newcommand{\FivePiExpanded}{5 \pi \arctan\left(\frac{y}{x}\right) - z}
\newcommand{\Denominator}{\left(\frac{\phi}{x^2}\right)}
% ----
\newcommand{\A}{%
-\frac{200 x^{2} {\left(\sqrt{\SQ} - 1\right)}}{{\left(\SQ\right)}^{\frac{3}{2}}} + \frac{200 x^{2}}{\SQ} + \frac{200 {\left(\sqrt{\SQ} - 1\right)}}{\sqrt{\SQ}} + \frac{2000 \pi {\FivePi} y}{x^{3} {\Denominator}} + \frac{5000 \pi^{2} y^{2}}{x^{4} {\Denominator}^{2}} - \frac{2000 \pi {\FivePi} y^{3}}{x^{5} {\Denominator}^{2}}%
}%
\newcommand{\B}{%
-\frac{200 x y {\left(\sqrt{\SQ} - 1\right)}}{{\left(\SQ\right)}^{\frac{3}{2}}} + \frac{200 x y}{\SQ} - \frac{1000 \pi {\FivePi}}{x^{2} {\Denominator}} - \frac{5000 \pi^{2} y}{x^{3} {\Denominator}^{2}} + \frac{2000 \pi {\FivePi} y^{2}}{x^{4} {\Denominator}^{2}}%
}
\newcommand{\C}{%
-\frac{200 x y {\left(\sqrt{\SQ} - 1\right)}}{{\left(\SQ\right)}^{\frac{3}{2}}} + \frac{200 x y}{\SQ} - \frac{1000 \pi {\FivePi}}{x^{2} {\Denominator}} - \frac{5000 \pi^{2} y}{x^{3} {\Denominator}^{2}} + \frac{2000 \pi {\FivePi} y^{2}}{x^{4} {\Denominator}^{2}}%
}
\newcommand{\D}{%
-\frac{200 y^{2} {\left(\sqrt{\SQ} - 1\right)}}{{\left(\SQ\right)}^{\frac{3}{2}}} + \frac{200 y^{2}}{\SQ} + \frac{200 {\left(\sqrt{\SQ} - 1\right)}}{\sqrt{\SQ}} + \frac{5000 \pi^{2}}{x^{2} {\Denominator}^{2}} - \frac{2000 \pi {\FivePi} y}{x^{3} {\Denominator}^{2}}%
}
\begin{document}
The matrix is as follows
\par\noindent
\scalebox{0.70}{\renewcommand{\arraystretch}{2.5}%%
$\left(\begin{array}{rrr}
\A & \B & \frac{1000 \pi y}{x^{2} {\Denominator}} \\
\C & \D & -\frac{1000 \pi}{x {\Denominator}} \\
\frac{1000 \pi y}{x^{2} {\Denominator}} & -\frac{1000 \pi}{x {\Denominator}} & 202
\end{array}\right)$}
where
\begin{align*}
\SQ &= \SQExpanded \\
\FivePi &= \FivePiExpanded
\end{align*}
An alternate solution is:
\[ \renewcommand{\arraystretch}{2.0}
\left(\begin{array}{ccc}
A & B & \frac{1000 \pi y}{x^{2} {\Denominator}} \\
C & D & -\frac{1000 \pi}{x {\Denominator}} \\
\frac{1000 \pi y}{x^{2} {\Denominator}} & -\frac{1000 \pi}{x {\Denominator}} & 202
\end{array}\right)
\]
where
\begin{align*}
A &= \A \\
B &= \B \\
C &= \C \\
D &= \D \\
\shortintertext{and}
\SQ &= \SQExpanded \\
\FivePi &= \FivePiExpanded
\end{align*}
\end{document}
I'm still confused about why you were confused. I essentially looked through the code for every "4" (or "3") and incremented. The only difficulty is that I couldn't have comments within the \addplot
.
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colormap={bluewhite}{color=(white) rgb255=(90,96,191)},
xlabel=Predicted,
xlabel style={yshift=-30pt},
ylabel=Actual,
ylabel style={yshift=20pt},
xticklabels={W1, W2, W3, W4, W5}, % changed
xtick={0,...,4}, % changed
xtick style={draw=none},
yticklabels={W1, W2, W3, W4, W5}, % changed
ytick={0,...,4}, % changed
ytick style={draw=none},
enlargelimits=false,
colorbar,
xticklabel style={
rotate=90
},
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta},
nodes near coords style={
yshift=-7pt
},
]
\addplot[
matrix plot,
mesh/cols=5, % changed
point meta=explicit,draw=gray
] table [meta=C] {
x y C
0 0 0.96
1 0 0.1
2 0 0
3 0 0
4 0 0
0 1 0.1
1 1 0.98
2 1 1
3 1 0.1
4 1 0.02
0 2 0
1 2 0
2 2 0.97
3 2 0.3
4 2 0
0 3 0.3
1 3 0
2 3 0
3 3 1
4 3 0.01
0 4 0
1 4 0
2 4 0.01
3 4 0
4 4 0.95
}; % added every entry where x=4 or y=4
\end{axis}
\end{tikzpicture}
\end{document}
For an output of
Best Answer