4

I am looking for some help fixing my matrix. I am trying to make the J in my matrix look like the one in the first picture. Also I am trying to add ellipsis to my matrix like the first picture and take away some of the clutter, looking for some help, thanks!

enter image description here

enter image description here

Here's a MWE of the code I wrote.

\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}
  • 2
    Welcome to TeX.SX! Have you tried \mathbb{J}? – TeXnician Apr 4 '18 at 16:54
  • 1
    will try that now! thanks, how about the ellipsis? – user104 Apr 4 '18 at 16:55
  • seem to be getting a error for that – user104 Apr 4 '18 at 16:56
  • 2
    to use \mathbb, you need to \usepackage{amsfonts}. – barbara beeton Apr 5 '18 at 0:37
  • The unicode-math package also defines \mathbb and practically every other math alphabet and symbol out there. I highly recommend it. – Davislor May 6 '18 at 21:38
1

Just missing the amssymb package in which is included the command \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}

enter image description here

  • 2
    +100000 thanks so much for completing this fully – user104 Apr 4 '18 at 17:11
  • in my document it seems like this matrix is being labelled? why? – user104 Apr 4 '18 at 17:15
  • 1
    could you edit and unlabel it? – user104 Apr 4 '18 at 17:35
  • 1
    That's a nice question and you should open a new topic for that, as it has to deal with the definition of the bmatrix environment in the package amsmath... I do not really know the answer, but I'm interested in the possible answer. Anyway if you're interested in a possible answer I've already asked for that here (in answer to the comment about the bottom spacing). – GiuTeX Apr 4 '18 at 17:36
  • 1
    @user104 you should consider of choosing a best answer! If I was useful to you I would appreciate that ;-) – GiuTeX Apr 5 '18 at 8:18
6

For the funny J load amssymb and type \mathbb{J}.

Also, do yourself a favor and define a command for the partial derivatives.

Final point, \\[1ex] gives some more breadth to the matrices, which is necessary here because of the big objects in them.

You had a missing } in one of the entries, which led to weird errors.

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

enter image description here

3

You need to use \mathbb{J} for the "J"; \cdots (horizontal dots),\vdots (vertical dots), and \ddots (diagonal dots) for the desired dots in the matrix.

  • I am getting an error from \mathbb{J} – user104 Apr 4 '18 at 17:00
  • 3
    You have to include the package \usepackage{amssymb}, to have the \mathbb... – GiuTeX Apr 4 '18 at 17:02
  • 1
    @Qinyu Cui I would recommend \cdots for the horizontal dots, as they're more central, and so more coherent with the disposition of \vdots. – GiuTeX Apr 4 '18 at 17:09
  • 1
    makes sense, edited. – anonIMOus Apr 4 '18 at 17:11
3

edit: added dots as you ask me in comment:

enter image description here

\documentclass{article}
\usepackage{nccmath, % <--- for "\mfrac", i.e. medium size "frac". it also load amsmath
            amssymb} % <--- for "\mathbb` font 

\begin{document}
\[\renewcommand\arraystretch{2} % <--- enlarge vertical space in matrix
\mathbb{J} =
\begin{bmatrix}
\mfrac{\partial V_H}{\partial V_H} & \mfrac{\partial V_H}{\partial S_H} &  \dotsm & \mfrac{\partial V_H}{\partial I_M} \\
\mfrac{\partial S_H}{\partial V_H} & \mfrac{\partial S_H}{\partial S_H} &  \dotsm & \mfrac{\partial S_H}{\partial I_M} \\
    \vdots & \vdots & \ddots & \vdots       \\
\mfrac{\partial R_H}{\partial V_H} & \mfrac{\partial R_H}{\partial S_H} &  \dotsm & \mfrac{\partial R_H}{\partial I_M} \\
\end{bmatrix}
\]
\end{document}

note: for shorter writing you can define new command as proposed in egreg answer as

\newcommand{\pder}[2]{\mfrac{\partial #1}{\partial #2}}
  • 1
    could you edit in the dots? – user104 Apr 4 '18 at 17:07
3

The other answers have already done a fine job of informing you that you need to load the amssymb package in order to access the \mathbb macro, so that you can write \mathbb{J}.

This answer provides a LuaLaTeX-based solution to the tedium of having to typeset the 7*7=49 elements (plus the & cell dividers and the \\ end-of-line markers) of the full Jacobian matrix. The code given below sets up a Lua function called jacobian_full. The core of this function a pair of nested for loops, with each loop running over 7 elements. What's appealing about this approach is that once one has set up the code for a 7x7 matrix, it's trivial to go on to typesetting either larger or smaller Jacobian matrices. All one has to do is modify the elements of the vars vector.

With this approach, there is but a single statement -- \directlua{jacobian_full()} -- between the \begin{bmatrix} and \end{bmatrix} statements. Compare this to the 2*49=98 directives (don't forget to count all those & and \\ directives!) that are needed in the standard approach.


This approach to typesetting the full 7x7 matrix may also be employed to typeset a "truncated" 4x4 matrix, in which the third row and third column are filled with suitably-oriented typographic ellipses ("triple dots"). The only thing that's substantially different between the Lua functions jacobian_full and jacobian_abbrv is that the former contains the single line

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

whereas in jacobian_abbrv, this single line gets replaced by a group of if statements, where the line above gets output only if the row and column indices i and j are both not equal to 3. If either i or j is equal to 3, \cdots/\vdots/\ddots is output, as appropriate.


enter image description here

% !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}
2

I propose this solution, which uses the esdiff package to simplify the typing of partial derivatives, and makecell to add some padding to the rows:

\documentclass{article}
\usepackage{amsmath, amsfonts}
\usepackage{esdiff}
\usepackage{array, makecell}

\begin{document}

\[%
\setcellgapes{3pt}\makegapedcells
\mathbb{J} =
\begin{bmatrix}
    \diffp{V_H}{{{V_H}}} & \diffp{V_H}{{{S_H}}} & \diffp{V_H}{{{I_H}}} & \diffp{V_H}{{{R_H}}} & \cdots &\diffp{V_H}{{{S_M}}} & \diffp{V_H}{{{E_M}}} & \diffp{V_H}{{I_M}} \\
\diffp{S_H}{{V_H}} & \diffp{S_H}{{S_H}} & \diffp{S_H}{{I_H}} & \diffp{S_H}{{R_H}} & \cdots & \diffp{S_H}{{S_M}} & \diffp{S_H}{{E_M}} & \diffp{S_H}{{I_M}} \\
 \diffp{I_H}{{V_H}} & \diffp{I_H}{{S_H}} & \diffp{I_H}{{I_H}} & \diffp{I_H}{{I_H}} & \cdots & \diffp{I_H}{{S_M}} & \diffp{I_H}{{E_M}} & \diffp{I_H}{{I_M}} \\
\diffp{R_H}{{V_H}} & \diffp{R_H}{{S_H}} & \diffp{R_H}{{I_H}} & \diffp{R_H}{{R_H}} & \cdots & \diffp{R_H}{{S_M}} & \diffp{R_H}{{E_M}} & \diffp{R_H}{{I_M}} \\[-6pt]
\vdots &\vdots &\vdots &\vdots & \cdots &\vdots &\vdots &\vdots \\[-13.66pt]
\vdots &\vdots &\vdots &\vdots & & \vdots &\vdots &\vdots \\[-1pt]
 \diffp{S_M}{{V_H}} & \diffp{S_M}{{S_H}} & \diffp{S_M}{{I_H}} & \diffp{S_M}{{R_H}} & \cdots& \diffp{S_M}{{S_M}} & \diffp{S_M}{{E_M}} & \diffp{S_M}{{I_M}} \\
 \diffp{E_M}{{V_H}} & \diffp{E_M}{{S_H}} & \diffp{E_M}{{I_H}} & \diffp{E_M}{{R_H}} & \cdots & \diffp{E_M}{{S_M}} & \diffp{E_M}{{E_M}} & \diffp{E_M}{{I_M}} \\
\diffp{I_M}{{V_H}} & \diffp{I_M}{{S_H}} & \diffp{I_M}{{I_H}} & \diffp{I_M}{{R_H}} & \cdots & \diffp{I_M}{{S_M}} & \diffp{I_M}{{E_M}} & \diffp{I_M}{{I_M}}
\end{bmatrix}
\]
\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.