# If definition of elements in table

I need to define a table where the definition of the elements differs if the indices $$i$$ and $$j$$ are equal or different. In particular I have to implement the following formula $$(K_1^{(1)}(m_1,m_2))_{ij} = \begin{cases} \frac{M_{ij}^{(1)}}{a_i-a_j}\left[\left(\frac{\alpha_s(m_2)}{\alpha_s(m_1)}\right)^{a_j}-\left(\frac{\alpha_s(m_2)}{\alpha_s(m_1)}\right)^{a_i}\right]&i\neq j\\ M_{ii}^{(1)}\left(\frac{\alpha_s(m_2)}{\alpha_s(m_1)}\right)^{a_i}\log\frac{\alpha_s(m_1)}{\alpha_s(m_2)} &i=j \end{cases}$$

All the relevant matrices have been defined as table and I need to define $$K_1^{(1)}$$. What I have done is as follows

K1 = Table[If[i == j, M15[[i, i]] (αsΛ/αsμ)^a5[[i]] Log[αsμ/αsΛ], M15[[i, j]]/(a5[[i]] - a5[[j]]) ((αsΛ/αsμ)^a5[[j]] - (αsΛ/αsμ)^a5[[i]])], {i, 1, 10}, {j, 1, 10}] // Chop


And what I get is various error of the form "Power: Infinite expression 1/0. encountered." and "Infinity: Indeterminate expression 0 ComplexInfinity encountered." which I imagine they would come from the program trying to evaluate the first expression even when $$i=j$$.

How do I solve this problem?

• Could you please add info. such asDimensions[M15] and Length[a5]? Or even these items, if possible.
– Syed
Sep 28, 2021 at 17:10
• @Syed Yes, dimensions[M15] outputs $\{10,10\}$ while length[a5] output $10$ Sep 28, 2021 at 17:12
• Can you ensure the ai does not equal aj?
– jmm
Sep 28, 2021 at 17:16
• Have you executed a MatrixForm command on M15 and a5 in your notebook prior to using these in the computation? It would be helpful to include these items in your post.
– Syed
Sep 28, 2021 at 17:17
• i.stack.imgur.com/WWXAy.png is the output of your command on my machine.
– Syed
Sep 28, 2021 at 17:24