I have a $4\times 4$ matrix (symbolic). It has a variable, say jj
, which should be $1$ for diagonal and $0$ for non-diagonal entries. I need to write a replacement rule which can do this. Now I am selecting each element and eliminating jj
separately using matrix[[1, 1]] /. jj -> 1
. But it's too tedious, and I am sure there must be some smarter way to do it.
The original matrix is too large and is very complex. I am writing a sample $3\times 3$ matrix over here:
A = {{2 AcD am g1*jj, jj + 1, 3 + g}, {jj + 2*g1, g1*jj,
AcD + jj}, {jj*g1, g1 + jj, AcD+jj*am}}
jj
always enter polynomially (e.g.c1 + c2 jj^2
), or can it be inside a more complicated function (e.g.c1 + c2 Log[jj]
)? $\endgroup$