用椭圆和 \mathbb 数学字母表排版矩阵

用椭圆和 \mathbb 数学字母表排版矩阵

我正在寻求帮助来修复我的矩阵。我试图让矩阵中的 J 看起来像第一张图片中的 J。我还试图像第一张图片一样在矩阵中添加省略号并消除一些混乱,寻求帮助,谢谢!

在此处输入图片描述

在此处输入图片描述

这是我编写的代码的 MWE。

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\[ J = 
\begin{bmatrix}
\frac{\partial V_H}{\partial V_H}    & \frac{\partial V_H}{\partial S_H} &  \frac{\partial V_H}{\partial I_H} &  \frac{\partial V_H}{\partial R_H} &\frac{\partial V_H}{\partial S_M} &  \frac{\partial V_H}{\partial E_M} &      \frac{\partial V_H}{\partial I_M} \\     
\frac{\partial S_H}{\partial V_H}    & \frac{\partial S_H}{\partial S_H} &  \frac{\partial S_H}{\partial I_H} & \frac{\partial S_H}{\partial R_H} &  \frac{\partial S_H}{\partial S_M} &  \frac{\partial S_H}{\partial E_M} &  \frac{\partial S_H}{\partial I_M} \\ 
\frac{\partial I_H}{\partial V_H}    & \frac{\partial I_H}{\partial S_H} &  \frac{\partial I_H}{\partial I_H} &  \frac{\partial I_H}{\partial I_H} &  \frac{\partial I_H}{\partial S_M} &  \frac{\partial I_H}{\partial E_M} &  \frac{\partial I_H}{\partial I_M} \\ 
\frac{\partial R_H}{\partial V_H}    & \frac{\partial R_H}{\partial S_H} &  \frac{\partial R_H}{\partial I_H} &  \frac{\partial R_H}{\partial R_H} &  \frac{\partial R_H}{\partial S_M} &  \frac{\partial R_H}{\partial E_M} &  \frac{\partial R_H}{\partial I_M} \\ 
\frac{\partial S_M}{\partial V_H}    & \frac{\partial S_M}{\partial S_H} &  \frac{\partial S_M}{\partial I_H} &  \frac{\partial S_M}{\partial R_H} &  \frac{\partial S_M}{\partial S_M} &  \frac{\partial S_M}{\partial E_M} &  \frac{\partial S_M}{\partial I_M} \\  
\frac{\partial E_M}{\partial V_H}    & \frac{\partial E_M}{\partial S_H} &  \frac{\partial E_M}{\partial I_H} &  \frac{\partial E_M}{\partial R_H} &  \frac{\partial E_M}{\partial S_M} &  \frac{\partial E_M}{\partial E_M} &  \frac{\partial E_M}{\partial I_M} \\  
\frac{\partial I_M}{\partial V_H}    & \frac{\partial I_M}{\partial S_H} &  \frac{\partial I_M}{\partial I_H} &  \frac{\partial I_M}{\partial R_H} &  \frac{\partial I_M}{\partial S_M} &  \frac{\partial I_M}{\partial E_M} &  \frac{\partial I_M}{\partial I_M} 
\end{bmatrix}
\]
\end{document}

答案1

只是缺少amssymb包含命令的包\mathbb{}

\documentclass{article}

\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
    \begin{equation}
        \renewcommand\arraystretch{2}
        \mathbb{J} = \begin{bmatrix}
            \frac{\partial V_H}{\partial V_H} & \frac{\partial V_H}{\partial I_H} & \cdots & \frac{\partial V_H}{\partial R_H} \\
            \frac{\partial V_H}{\partial V_H} &\frac{\partial V_H}{\partial I_H} & \cdots & \frac{\partial V_H}{\partial R_H} \\
            \vdots & \vdots & \ddots & \vdots \\
            \frac{\partial V_H}{\partial V_H} & \frac{\partial V_H}{\partial I_H} & \cdots & \frac{\partial V_H}{\partial R_H} \\
        \end{bmatrix}
    \end{equation}

    %UNLABELLED VERSION
    \[
        \renewcommand\arraystretch{2}
        \mathbb{J} = \begin{bmatrix}
            \frac{\partial V_H}{\partial V_H} & \frac{\partial V_H}{\partial I_H} & \cdots & \frac{\partial V_H}{\partial R_H} \\
            \frac{\partial V_H}{\partial V_H} &\frac{\partial V_H}{\partial I_H} & \cdots & \frac{\partial V_H}{\partial R_H} \\
            \vdots & \vdots & \ddots & \vdots \\
            \frac{\partial V_H}{\partial V_H} & \frac{\partial V_H}{\partial I_H} & \cdots & \frac{\partial V_H}{\partial R_H} \\
        \end{bmatrix}
    \]
\end{document}

在此处输入图片描述

答案2

对于有趣的 J 负载amssymb和类型\mathbb{J}

另外,帮自己一个忙,为偏导数定义一个命令。

最后一点,\\[1ex]给矩阵提供更多的广度,这是必要的,因为矩阵中包含较大的对象。

您缺少了}其中一个条目,这导致了奇怪的错误。

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

\newcommand{\pder}[2]{\frac{\partial #1}{\partial #2}}

\begin{document}

With ellipsis
\[
\mathbb{J} =
\begin{bmatrix}
\pder{f_1}{X_1} & \pder{f_1}{X_2} & \dots & \pder{f_1}{X_n} \\[1ex]
\pder{f_2}{X_1} & \pder{f_2}{X_2} & \dots & \pder{f_2}{X_n} \\
\vdots & \vdots & \ddots & \vdots \\[1ex]
\pder{f_n}{X_1} & \pder{f_n}{X_2} & \dots & \pder{f_n}{X_n}
\end{bmatrix}
\]
and full
\[
\mathbb{J} =
\begin{bmatrix}
\pder{V_H}{V_H} & \pder{V_H}{S_H} & \pder{V_H}{I_H} & \pder{V_H}{R_H} &
  \pder{V_H}{S_M} & \pder{V_H}{E_M} & \pder{V_H}{I_M} \\[1ex]
\pder{S_H}{V_H} & \pder{S_H}{S_H} & \pder{S_H}{I_H} & \pder{S_H}{R_H} &
  \pder{S_H}{S_M} & \pder{S_H}{E_M} & \pder{S_H}{I_M} \\[1ex]
\pder{I_H}{V_H} & \pder{I_H}{S_H} & \pder{I_H}{I_H} & \pder{I_H}{I_H} &
  \pder{I_H}{S_M} & \pder{I_H}{E_M} & \pder{I_H}{I_M} \\[1ex]
\pder{R_H}{V_H} & \pder{R_H}{S_H} & \pder{R_H}{I_H} & \pder{R_H}{R_H} &
  \pder{R_H}{S_M} & \pder{R_H}{E_M} & \pder{R_H}{I_M} \\[1ex]
\pder{S_M}{V_H} & \pder{S_M}{S_H} & \pder{S_M}{I_H} & \pder{S_M}{R_H} &
  \pder{S_M}{S_M} & \pder{S_M}{E_M} & \pder{S_M}{I_M} \\[1ex]
\pder{E_M}{V_H} & \pder{E_M}{S_H} & \pder{E_M}{I_H} & \pder{E_M}{R_H} &
  \pder{E_M}{S_M} & \pder{E_M}{E_M} & \pder{E_M}{I_M} \\[1ex]
\pder{I_M}{V_H} & \pder{I_M}{S_H} & \pder{I_M}{I_H} & \pder{I_M}{R_H} &
  \pder{I_M}{S_M} & \pder{I_M}{E_M} & \pder{I_M}{I_M}
\end{bmatrix}
\]
\end{document}

在此处输入图片描述

答案3

您需要使用\mathbb{J}“J”;\cdots(水平点)、\vdots(垂直点)和\ddots(对角点)表示矩阵中所需的点。

答案4

其他答案已经很好地告知您需要加载amssymb包才能访问\mathbb宏,以便您可以编写\mathbb{J}

此答案提供了一个基于 LuaLaTeX 的解决方案,解决了必须排版完整雅可比矩阵的7*7=49 个元素(加上&单元格分隔符和行尾标记)的繁琐工作。下面给出的代码设置了一个名为的 Lua 函数。此函数的核心是一对嵌套循环,每个循环运行 7 个元素。这种方法的吸引力在于,一旦为 7x7 矩阵设置了代码,就可以很轻松地继续排版更大或更小的雅可比矩阵。所要做的就是修改向量的元素。\\jacobian_fullforvars

使用这种方法, and语句\directlua{jacobian_full()}之间只有一个语句 -- -- 。相比之下,标准方法需要2*49=98 个指令(不要忘记计算所有这些and指令!)。\begin{bmatrix}\end{bmatrix}&\\


这种排版完整 7x7 矩阵的方法也可用于排版“截断的”4x4 矩阵,其中第三行和第三列填充了方向合适的排版椭圆(“三个点”)。Lua 函数和 7x7 函数之间唯一实质性的不同是,jacobian_full前者jacobian_abbrv包含一行

tex.sprint ( "\\pder{" .. vars[i] .."}{" .. vars[j] .."}" )

而在 中jacobian_abbrv,这一行被一组语句取代,其中仅当行和列索引和都不等于if时,上面的行才会输出。如果 或等于,则根据需要输出/ / 。ij3ij3\cdots\vdots\ddots


在此处输入图片描述

% !TeX program=lualatex

\RequirePackage{filecontents}

%% Place the Lua code in an external file
\begin{filecontents*}{jacobians.lua}
-- Function to output "&" or "\\" after each cell
function cell_terminate ( i,j,N )
  if j<N then
    tex.sprint ( "&" )
  elseif i<N then
    tex.sprint ( "\\\\" )
  end
end

-- Function to print the full Jacobian matrix
function jacobian_full()
  -- Modify the following Lua table as needed:
  vars = { "V_H","S_H","I_H","R_H","S_M","E_M","I_M" }
  for i = 1,#vars do
    for j = 1,#vars do
      tex.sprint ("\\pder{"..vars[i].."}{"..vars[j].."}")
      cell_terminate(i,j,#vars)
    end
  end
end

-- Function to print the abbreviated Jacobian matrix
function jacobian_abbrv()
  -- Third element of 'vars' is arbitrary:
  vars = { "V_H", "S_H", "xyz", "I_M" }
  for i = 1,#vars do
    for j = 1,#vars do
      if i==3 and not (j==3) then 
        tex.sprint ("\\vdots")
      elseif j==3 and not (i==3) then
        tex.sprint ("\\cdots")
      elseif i==3 and j==3 then
        tex.sprint ("\\ddots")  
      else
        tex.sprint ("\\pder{"..vars[i].."}{"..vars[j].."}")
      end
      cell_terminate(i,j,#vars)
    end
  end
end
\end{filecontents*}

\documentclass{article}
\usepackage{amsmath} % for 'bmatrix' environment
\usepackage{amssymb} % for '\mathbb' macro
\newcommand\pder[2]{\frac{\partial #1}{\partial #2}}
\directlua{dofile 'jacobians.lua'} % load the Lua code

\begin{document}
%% Print the full and abbreviated Jacobians
\renewcommand\arraystretch{1.333}
\begin{gather*}
\mathbb{J}  = \begin{bmatrix} 
                 \directlua{ jacobian_full() } 
              \end{bmatrix} \\[3ex]
\mathbb{J}' = \begin{bmatrix} 
                 \directlua{ jacobian_abbrv() } 
              \end{bmatrix}
\end{gather*}
\end{document}

相关内容