0
$\begingroup$

I have two matrices - s1 and s2.

I want their sum to remain unevaluated.

For instance, the command

s1 + s2 // MatrixForm

should result to two separate matrices joined by the plus operator.

I guess that I have to wrap s1 + s2 inside a function like Hold or Unevaluated, but I cannot find the proper workaround.

Any ideas?

$\endgroup$
13
  • $\begingroup$ Perhaps Inactivate[MatrixForm[s1] + MatrixForm[s2], Plus] $\endgroup$
    – ilian
    May 7, 2015 at 11:38
  • $\begingroup$ Sektor, thanks for the required modifications. I totally forgot them:-)! $\endgroup$
    – Dimitris
    May 7, 2015 at 11:41
  • $\begingroup$ Hi, ilian and thank you. Is there any alternative for versions prior to 10? $\endgroup$
    – Dimitris
    May 7, 2015 at 11:45
  • $\begingroup$ If just for display purposes, maybe Row[{MatrixForm[s1] , "+", MatrixForm[s2]}] ? $\endgroup$
    – ilian
    May 7, 2015 at 11:48
  • 1
    $\begingroup$ for V < 10: 31727 $\endgroup$
    – Kuba
    May 7, 2015 at 11:54

1 Answer 1

1
$\begingroup$
s1 = {{8, 6, 6, 1}, {9, 8, 4, 4}, {5, 3, 5, 5}, {10, 5, 6, 2}};
s2 = {{9, 1, 10, 5}, {1, 9, 1, 3}, {8, 4, 4, 9}, {2, 9, 6, 2}};
Apply[
 HoldForm[#1 + #2] &, 
 MapThread[List, {s1, s2}, 2], {2}] // MatrixForm

$\left( \begin{array}{cccc} 8+9 & 6+1 & 6+10 & 1+5 \\ 9+1 & 8+9 & 4+1 & 4+3 \\ 5+8 & 3+4 & 5+4 & 5+9 \\ 10+2 & 5+9 & 6+6 & 2+2 \\ \end{array} \right)$

Or

SetAttributes[plus, Listable]
Apply[
 HoldForm[#1 + #2] &, plus[s1, s2], {2}] // MatrixForm

(same result)

$\endgroup$
0

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