使用 drawmatrix 可视化 QR 分解

使用 drawmatrix 可视化 QR 分解

我正在使用drawmatrix包,我想说明以下内容图片

在此处输入图片描述

这是我的尝试

\documentclass{article}
\usepackage{drawmatrix}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}


A matrix $A\in\mathbb{R}^{m\times n}$, $m\geq n$, can be factorized
into $A=QR$ where $Q\in\mathbb{R}^{m\times m}$ is orthogonal,
$R\equiv\begin{bmatrix}\widehat{R}\\0\end{bmatrix}\in\mathbb{R}^{m\times n}$,
$\widehat{R}\in\mathbb{R}^{n\times n}$ is upper triangular.

\[
    \drawmatrix[width=1.2, height=2]{A}=
    \drawmatrix[width=2, height=2, fill=yellow!10]{Q}\;
    \drawmatrix[width=1.2, height=1.2, upper, bbox style={fill=green!10}]{\widehat{R}}
    \drawmatrix[width=1.2, height=1]{0}
\]

\end{document}

在此处输入图片描述

答案1

主要的

这有用吗?代码包含@Willie Wong 的建议。

代码

\documentclass{article}
\usepackage{drawmatrix}
\usetikzlibrary{calc, tikzmark}
\usepackage{amsmath}
\usepackage{amssymb}

\xdefinecolor{B}{RGB}{0, 102, 221}
\begin{document}

\noindent
A matrix $A \in \mathbb{R}^{m\times n}$, $m\geq n$, can be factorized
into $A=QR$ where $Q\in\mathbb{R}^{m\times m}$ is orthogonal,
$R = \begin{bmatrix}\widehat{R}\\0\end{bmatrix} \in \mathbb{R}^{m\times n}$
with $\widehat{R} \in \mathbb{R}^{n\times n}$ upper triangular.

\drawmatrixset{%
  black!40, fill=B!30,
  bbox style={draw, black!40}
}
\[
  \drawmatrix[width=1.2, height=2]{A}
  = \drawmatrix[width=2, height=2]{Q}
  \;\tikzmark{tmp}\;
  \drawmatrix[width=1.2, height=1.2,
  upper, bbox height=2]{R}
  = \drawmatrix[width=1.2, height=2]{\widehat{Q}} \;
  \drawmatrix[width=1.2, height=1.2, upper]{\widehat{R}}.
\]
\begin{tikzpicture}[overlay, remember picture]
    \path
    ($(pic cs:tmp) +(-1pt, 2pt)$)
    node[draw, dashed, left,
    minimum width=.9cm, minimum height=2.2cm] {};
    \path 
    ($(pic cs:tmp) +(1pt, -.12)$)
    node[draw, dashed, below right,
    minimum width=1.3cm, minimum height=.9cm] {};
\end{tikzpicture}
\end{document}

相关内容