1

I've got a State-Space system (4 matrices that go together), and rather than presenting each SS matrix on a new line I would like to group them together (and look nice while doing so).

I'm looking for the best way to do this.

The following code contains my 4 matrices (and works), but I encounter the following problems:

  1. When I put \begin{equation} \end{equation} around my code it gives errors

  2. All matrices have different sizes. Is there some way to make the formatting more pretty?

enter image description here

\documentclass[11pt,a4paper]{article}
\begin{document}
$\begin{array}{ll}

A = \left[\begin{array}{cccc}
0&0&1&0\\
0&0&0&1\\
\frac{-k}{J_1}&\frac{k}{J_1}&\frac{-d}{J_1}&\frac{d}{J_1}\\
\frac{k}{J_2}&\frac{-k}{J_2}&\frac{d}{J_2}&\frac{-d}{J_2}
\end{array}\right] & B = \left[\begin{array}{c}
0\\0\\\frac{1}{J_1}\\0
\end{array}\right]  \\
C = \left[\begin{array}{cccc}0&0&1&0\end{array}\right]& D = \left[\begin{array}{c}0\end{array}\right]\\

\end{array}$
\end{document}

The above code is an array size 2x2 with arrays on all elements. I've considered using

\begin{equation}
\begin{split}
A & =matrix1 B=matrix2 \\
C & =matrix3 C=matrix4
\end{split}
\end{equation

But this wont even compile.

2

2 Answers 2

1

The hard part was using the same horizontal spacing in each array.

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}

\newcommand{\cell}[1]{\makebox[15pt]{#1}}% adjust column widths

\begin{document}
\def\arraystretch{1.4}% adjust row spacing
\begin{align*}
A &= \begin{bmatrix}
\cell{0}&\cell{0}&\cell{1}&\cell{0}\\ % set spacing for one row
0&0&0&1\\
\frac{-k}{J_1}&\frac{k}{J_1}&\frac{-d}{J_1}&\frac{d}{J_1}\\
\frac{k}{J_2}&\frac{-k}{J_2}&\frac{d}{J_2}&\frac{-d}{J_2}
\end{bmatrix} & B &= \begin{bmatrix}
\cell{0}\\0\\\frac{1}{J_1}\\0
\end{bmatrix}  \\
C &= \:\begin{bmatrix} \cell{0}&\cell{0}&\cell{1}&\cell{0} \end{bmatrix} & D &= \:\begin{bmatrix} \cell{0} \end{bmatrix}\\
\end{align*}
\end{document}

demo

3
  • Thanks your result looks very nice, however this will not compile. (placed in a new texfile to be sure and it gives over 20 errors).
    – Niwol
    Sep 8, 2016 at 9:38
  • Got it to compile (the empty line after \begin{align} should be removed.
    – Niwol
    Sep 8, 2016 at 9:52
  • using it within \begin{equation} \end{equation} and using aligned instead of align* gave the desired final result. Thanks!
    – Niwol
    Sep 8, 2016 at 11:03
2

Like this?

enter image description here

well, above image is drawn by:

\documentclass[a4paper]{article}
    \usepackage{tikz}
    \usetikzlibrary{matrix, positioning}

    \begin{document}
\begin{tikzpicture}[node distance=3mm,
    every node/.style = {inner xsep=0pt,
                         minimum width=2em, minimum height=3ex},
every  left delimiter/.style={xshift=1em},
every right delimiter/.style={xshift=-1em}
                    ]
\matrix (m11) [matrix of math nodes,%
               {left delimiter=[},{right delimiter=]}] 
{
    0   &   0   &   1   &   0           \\
    0   &   0   &   0   &   1           \\
    \frac{-k}{J_1}
        &   \frac{k}{J_1}
                &   \frac{-d}{J_1}
                    &   \frac{d}{J_1}   \\
    \frac{k}{J_2}
        &   \frac{-k}{J_2}
            &   \frac{d}{J_2}
                &   \frac{-d}{J_2}      \\
}; 
\node (n11) [left=of m11]   {$A =$};

\node (n12) [right=7mm of m11] {$B =$};
\matrix (m12) [matrix of math nodes,%
               {left delimiter=[},{right delimiter=]},%
               right=of n12]
{
    0   \\  0   \\  \frac{k}{J_1}   \\  0   \\
};
% second row
\matrix (m21) [matrix of math nodes, inner ysep=1mm,%
               {left delimiter=[},{right delimiter=]},%
               below=of m11]
{
    0   &   0   &   1   &   0   \\
};    
\node (n21) [left=of m21] {$C =$};
\node (n22) [right=7mm of m21] {$D =$};
\matrix (m22) [matrix of math nodes, inner ysep=1mm,%
               {left delimiter=[},{right delimiter=]},%
               right=of n22]
{
    0   \\
};

    \end{tikzpicture}
\end{document}

Addedndum: above picture you can enclose in math environment. for better positioning of equation number you need to add baseline=(current bounding box.center) option to tikzpicture:

\documentclass[a4paper]{article}
    \usepackage{tikz}
    \usetikzlibrary{matrix, positioning}

    \begin{document}
    \begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center),

 %... the same as in MWE above ...

    \end{tikzpicture}
    \end{equation}
\end{document}

enter image description here

2
  • Looks very nice and it compiles without problems! Would there be someway to put it in an \begin{equation} \end{equation} environment?
    – Niwol
    Sep 8, 2016 at 9:40
  • @Niwol, of course, it is possible, See addendum in my answer.
    – Zarko
    Sep 8, 2016 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .