[Tex/LaTex] Column sums in matrix array

matrices

I am trying to get my equation to look like the following:

enter image description here

I cannot seem to get anywhere close (is there a way to get labels in \bordermatrix to go at the bottom?). Here is my code so far (without the dotted line and column totals)

\begin{eqnarray} 
P^{\ast}_{t+1} &=& P_{t+1} + D_{t,t+1} - B_{t,t+1} \\ \nonumber
&=&
\left(
\begin{array}{llll}
1110 &  110 &    10 &   10  \\
  45 &  440 &    45 &    0  \\
  70 &   75 &   770 &   70  \\
  35 &   30 &    30 &  330  \\
\end{array}
\right) + 
\left(
\begin{array}{llll}
44.05 &   3.36 &   0.53 &   0.24  \\
 1.79 &  13.44 &   2.37 &   0.00  \\
 2.78 &   2.29 &  40.53 &   1.71  \\
 1.39 &   0.92 &   1.58 &   8.05  \\
\end{array}
\right) - 
\left(
\begin{array}{llll}
80 &     0 &     0 &     0 \\
 0 &    25 &     0 &     0 \\
 0 &     0 &    40 &     0 \\
 0 &     0 &     0 &    40 \\
\end{array}
\right)
\end{eqnarray}

Best Answer

Here is one way of obtained the desired output:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{arydshln}% http://ctan.org/pkg/arydshln
\newcommand{\addsum}[1]{%
  \mathstrut\smash{\begin{array}[t]{@{}r@{}}#1\end{array}}%
}
\begin{document}
\begin{align*} 
  P^{\ast}_{t+1} &= P_{t+1} + D_{t,t+1} - B_{t,t+1} \\
    &=
    \left(
      \begin{array}{rrrr}
        1110 &  110 &    10 &   10 \\
          45 &  440 &    45 &    0 \\
          70 &   75 &   770 &   70 \\
          35 &   30 &    30 &  330
      \end{array}
     \right) + 
     \left(
       \begin{array}{rrrr}
         44.05 &   3.36 &   0.53 &   0.24 \\
          1.79 &  13.44 &   2.37 &   0.00 \\
          2.78 &   2.29 &  40.53 &   1.71 \\
          \addsum{1.39\\50.01} & 
          \addsum{0.92\\20.01} & 
          \addsum{1.58\\45.01} & 
          \addsum{8.05\\10.00} \\ \hdashline
       \end{array}
      \right) - 
      \left(
        \begin{array}{rrrr}
          80 &     0 &     0 &     0 \\
           0 &    25 &     0 &     0 \\
           0 &     0 &    40 &     0 \\
           0 &     0 &     0 &    40
        \end{array}
      \right)
\end{align*}
\end{document}

I modified the alignment to be right for the four columns. With some more work, it would be possible to obtain a centred sum.

The totals are added on a per-column basis using \addsum where you specify the information contained in the last and "sum" row. The arydshln package provides the dashed rule. Alternatively, using \hline within \addsum instead of \hdashline yields the following output:

enter image description here

%...
 \left(
   \begin{array}{rrrr}
     44.05 &   3.36 &   0.53 &   0.24 \\
      1.79 &  13.44 &   2.37 &   0.00 \\
      2.78 &   2.29 &  40.53 &   1.71 \\
      \addsum{1.39\\\hline 50.01} & 
      \addsum{0.92\\\hline 20.01} & 
      \addsum{1.58\\\hline 45.01} & 
      \addsum{8.05\\\hline 10.00}
   \end{array}
  \right) - 
%...

In both instances, \smash removes all vertical height/depth of its contents. As such, be careful when adding contents below this expression. Adding a blank row in the form \\& would mostly suffice.