Mathematica Asked by Rob on July 31, 2020

Given two matrices $A$ and $B$, their Binomial expansion is, in general, given by (see this page)

$(A+B)^n = sumlimits_{k=0, k=n[2]}^n Bigg( sumlimits_{r=0}^k binom{k}{r} A^r B^{k-r} Bigg) Bigg(frac{-C}{2}Bigg)^{frac{n-k}{2}} frac{n!}{k!(frac{n-k}{2})!}$

Here, $C=AB-BA$, is the commutator of $A$ and $B$. For `matM = {{m11, m12}, {m21, m22}}; matN = {{n11, n12}, {n21, n22}};`

, how can one implement the above formula in *Mathematica*, say for simple case with $n=2$?

```
commutator[a_, b_] := a.b - b.a
mtxbinomial[a_, b_, n_] :=
Block[{c = commutator[a, b], zeros = ConstantArray[0, Dimensions[a]]},
If[c == zeros,
Message[commutator::args, "Matrices A and B commute!"]; Abort[]
];
Sum[
If[Mod[k, 2] == Mod[n, 2],
Sum[Binomial[k, r] MatrixPower[a, r].MatrixPower[b, k - r], {r, 0, k}].
MatrixPower[-c/2, (n - k)/2]*n!/(k! ((n - k)/2)!),
zeros],
{k, 0, n}]]
```

Testing $(A+B)^2$ gives `True`

for some random matrices:

```
a = RandomReal[{-1, 1}, {5, 5}];
b = RandomReal[{-1, 1}, {5, 5}];
expected = MatrixPower[a + b, 2];
mtxbinomial[a, b, 2] == expected
```

Answered by flinty on July 31, 2020

1 Asked on May 27, 2021 by donald-obama

0 Asked on May 26, 2021 by r-y-zhao

2 Asked on May 26, 2021

1 Asked on May 26, 2021 by chuannan-li

0 Asked on May 26, 2021

2 Asked on May 26, 2021 by matt-f

1 Asked on May 26, 2021 by lele

differential equations list manipulation performance tuning table

2 Asked on May 26, 2021

1 Asked on May 25, 2021

differential equations equation solving nonlinear numerical integration singularity

0 Asked on May 25, 2021 by gbd

1 Asked on May 25, 2021 by r-hall

0 Asked on May 25, 2021

1 Asked on May 25, 2021 by antonio-j-gmez

1 Asked on May 25, 2021 by rodion-stepanov

1 Asked on May 24, 2021 by the_lar

Get help from others!

Recent Questions

- How Do I Get The Ifruit App Off Of Gta 5 / Grand Theft Auto 5
- Iv’e designed a space elevator using a series of lasers. do you know anybody i could submit the designs too that could manufacture the concept and put it to use
- Need help finding a book. Female OP protagonist, magic
- Why is the WWF pending games (“Your turn”) area replaced w/ a column of “Bonus & Reward”gift boxes?
- Does Google Analytics track 404 page responses as valid page views?

Recent Answers

- Peter Machado on Why fry rice before boiling?
- Joshua Engel on Why fry rice before boiling?
- Jon Church on Why fry rice before boiling?
- Lex on Does Google Analytics track 404 page responses as valid page views?
- haakon.io on Why fry rice before boiling?

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP