# How to write a Jacobian matrix in LaTeX

I am using LaTeX to write this Jacobian matrix:

\mathbf{u_{i,j}}=\left[\begin{array}{ccc}
\frac{\partial u_1}{\partial x_1} & \frac{\partial u_1}{\partial x_2} & \frac{\partial u_1}{\partial x_3} \\
\frac{\partial u_2}{\partial x_1} & \frac{\partial u_2}{\partial x_2} & \frac{\partial u_2}{\partial x_3 \\
\frac{\partial u_3}{\partial x_1} & \frac{\partial u_3}{\partial x_2} & \frac{\partial u_3}{\partial x_3
\end{array}\right],


But it is not compiling.

How can I write this?

@Sebastiano's answer shows what you need to do to get the code to compile without error or warning messages. In order to make the matrix easier to read and more visually appealing, you may additionally want to (a) increase the amount of whitespace between rows and (b) employ a bmatrix environment (provided by the amsmath package) instead of the basic array environment to typeset the matrix more compactly -- specifically, with less space between the square brackets and the matrix itself.

\documentclass{article}
\usepackage{amsmath} % for 'bmatrix' environment
\begin{document}
$\mathbf{u}_{i,j} = \begin{bmatrix} \frac{\partial u_1}{\partial x_1} & \frac{\partial u_1}{\partial x_2} & \frac{\partial u_1}{\partial x_3} \\[1ex] % <-- 1ex more space between rows of matrix \frac{\partial u_2}{\partial x_1} & \frac{\partial u_2}{\partial x_2} & \frac{\partial u_2}{\partial x_3} \\[1ex] \frac{\partial u_3}{\partial x_1} & \frac{\partial u_3}{\partial x_2} & \frac{\partial u_3}{\partial x_3} \end{bmatrix}$
\end{document}


Similar to Mico's answer...

However for shorter writing of code, use the physics package:

\documentclass{article}
\usepackage{amsmath} % for 'bmatrix' environment
\usepackage{physics} % for 'pdv' macro

\begin{document}
$\renewcommand\arraystretch{1.6} \mathbf{u}_{i,j} = \begin{bmatrix} \pdv{u_1}{x_1} & \pdv{u_1}{x_2} & \pdv{u_1}{x_3} \\%[1ex] % <-- 1ex more space between rows of matrix \pdv{u_2}{x_1} & \pdv{u_2}{x_2} & \pdv{u_2}{x_3} \\%[1ex] \pdv{u_3}{x_1} & \pdv{u_3}{x_2} & \pdv{u_3}{x_3} \end{bmatrix}$
\end{document}


First off, you have two syntax errors, viz., two instances of missing } (right-hand curly braces) after \partial x_3. Second, the array environment must be placed in math mode.

\documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}

$\mathbf{u_{i,j}}=\left[\begin{array}{ccc} \frac{\partial u_1}{\partial x_1} & \frac{\partial u_1}{\partial x_2} & \frac{\partial u_1}{\partial x_3} \\ \frac{\partial u_2}{\partial x_1} & \frac{\partial u_2}{\partial x_2} & \frac{\partial u_2}{\partial x_3} \\ \frac{\partial u_3}{\partial x_1} & \frac{\partial u_3}{\partial x_2} & \frac{\partial u_3}{\partial x_3} \end{array}\right]$
\end{document}