Is there a procedure for finding all matrices which commute with two given square and complex matrices?


For example, given two elements $A,B \in$ $\mathfrak{su}(4)$ is it possible to find all elements which commute with both $A$ and $B$ individually.



Finding commuting matrices
Generically (e.g., if one of the matrices has distinct eigenvalues, or more generally, is non-derogatory; for two commuting matrices, the conditions are even weaker), the centralizer of a single matrix just consists of the polynomials in that matrix. So if you pick a pair of commuting matrices at random, the polynomials in them will almost always suffice. 


But if you select a random pair of matrices (not commuting), generically they will generate the entire matrix algebra, and so the centralizer will consist of the scalar matrices. 


Of course, if you're being picky, you have to look at common invariant subspaces, a nuisance.


