# Assigning some results after a solve procedure to the coefficients of a matrix

I have a matrix M[3,3]. After a solve procedure, I obtained these results.

{{M[1, 2] -> Cos[ψ[t]], M[1, 3] -> 0, M[2, 3] -> 0, Cos[θ[t]] -> M[3, 1], M[3, 2] -> 0, M[3, 3] -> 1, M[2, 1] -> -Cos[ψ[t]] Sin[θ[t]], M[2, 2] -> Sin[ψ[t]], M[1, 1] -> Sin[θ[t]] Sin[ψ[t]]}}

I would like to assign the all the parameters M[1,1], M[1,2], ... to the coefficients of my matrix.

How can I assign the different coefficients obtained in order to be able to evaluate the matrix M ?

I use Mathematica 10, so may be the Values function can be useful but I didn't manage to use it correctly for this purpose for the moment.

Thank you for your help. But, I have still some difficulties. In fact, the function SolveAlways give me some rules but sometimes, these rules are not in the good direction (Cos[θ[t]] -> M[3, 1]). Consequently, I believe that it is the cause of a difficulties link to the assignments of the coefficients of the matrix.

Thread[Array[M, {3, 3}].ϵ == ω]

{{M[1, 2] -> Cos[ψ[t]], M[1, 3] -> 0, M[2, 3] -> 0,
Cos[θ[t]] -> M[3, 1], M[3, 2] -> 0, M[3, 3] -> 1,
M[2, 1] -> -Cos[ψ[t]] Sin[θ[t]],
M[2, 2] -> Sin[ψ[t]],
M[1, 1] -> Sin[θ[t]] Sin[ψ[t]]}}

soln = SolveAlways[%, ϵ]

{{M[1, 2] -> Cos[ψ[t]], M[1, 3] -> 0, M[2, 3] -> 0,
Cos[θ[t]] -> M[3, 1], M[3, 2] -> 0, M[3, 3] -> 1,
M[2, 1] -> -Cos[ψ[t]] Sin[θ[t]],
M[2, 2] -> Sin[ψ[t]],
M[1, 1] -> Sin[θ[t]] Sin[ψ[t]]}}

matrix = Array[M, {3, 3}]

{{M[1, 1], M[1, 2], M[1, 3]}, {M[2, 1], M[2, 2], M[2, 3]}, {M[3, 1],
M[3, 2], M[3, 3]}}

M = matrix /. soln

Hold[{{Sin[θ[t]] Sin[ψ[t]], Cos[ψ[t]],
0}, {-Cos[ψ[t]] Sin[θ[t]], Sin[ψ[t]],
0}, {M[3, 1], 0, 1}}]


matrix = Array[M, {3, 3}];

soln = {{M[1, 2] -> Cos[\[Psi][t]], M[1, 3] -> 0, M[2, 3] -> 0,
Cos[\[Theta][t]] -> M[3, 1], M[3, 2] -> 0, M[3, 3] -> 1,
M[2, 1] -> -Cos[\[Psi][t]] Sin[\[Theta][t]],
M[2, 2] -> Sin[\[Psi][t]],
M[1, 1] -> Sin[\[Theta][t]] Sin[\[Psi][t]]}};


To reverse rules that are in "wrong" direction:

soln = If[Head[#[[1]]] === M, #, Reverse[#]] & /@ soln[[1]]


{M[1, 2] -> Cos[[Psi][t]], M[1, 3] -> 0, M[2, 3] -> 0, M[3, 1] -> Cos[[Theta][t]], M[3, 2] -> 0, M[3, 3] -> 1, M[2, 1] -> -Cos[[Psi][t]] Sin[[Theta][t]], M[2, 2] -> Sin[[Psi][t]], M[1, 1] -> Sin[[Theta][t]] Sin[[Psi][t]]}

matrix /. soln


{{Sin[[Theta][t]] Sin[[Psi][t]], Cos[[Psi][t]], 0}, {-Cos[[Psi][t]] Sin[[Theta][t]], Sin[[Psi][t]], 0}, {Cos[[Theta][t]], 0, 1}}

• Thank you for your help. But i have still some difficulties to apply this code. I add some modifications in my post as regard to the initial post. I suppose the difficulty should come from the fact that the results of the function SolveAlways are not all in the good directions. – Bendesarts Mar 6 '15 at 9:35
• See edit above. – Bob Hanlon Mar 6 '15 at 14:06
• Great. You perfectly help me. Thanks a lot. – Bendesarts Mar 6 '15 at 15:25