# Lists and Matrices

I have a matrix of the form:

 matrix ={{a,b},{10*a,10*b}}.


I want to evaluate this matrix for a set of values. For example:

 list = {{1,2},{3,4},{5,6},{7,8},{9,10}},


where each sublist has the values of $a$ and $b$ respectively. How would I go about evaluating the matrix at the values in the list?

Edit:

More specifically, I have a list of the form:

OptimalPoints = {
{
2.257542266902225631614619931003504496483266177646115.*^-8,
1.5707963962277623797333694380851343630415.
},
{
6.503005757837946013321181089385241784765455399669815.*^-8,
1.5707963000375440696704763025083935974315.
},
{
0,
1.5707962573776482361594390149019628187115.
}
}


and the matrix is derived from the code:

J = 1;

Clear[ψ]
ψ[α_, χ_] := Exp[I α]*Tan[χ/2];

newcoherentstate[α_, χ_, m_] := ((ψ[α, χ])/(1 + ψ[α, χ]*
Simplify[
Conjugate[ψ[α, χ]],
Assumptions -> {Element[α, Reals], Element[χ, Reals]}
]))^(J) *(ψ[α, χ])^(m)*Sqrt[Binomial[2 J, J + m]];

TempNewMatrix [α_, χ_] := Simplify[
Table[
newcoherentstate[α, χ, m],
{m, J, -J, -1}
],
Assumptions -> {Element[α, Reals], Element[χ, Reals]}
];

NewMatrix [α_, χ_] := ArrayReshape[TempNewMatrix [α, χ], {2*J + 1, 1}];

NewMatrix1[α_, χ_] := ArrayReshape[NewMatrix[α, χ], {1, 2*J + 1}]

NewMatrixC[α_, χ_] := Simplify[
Conjugate[NewMatrix1[α, χ]],
Assumptions ->{Element[α, Reals], Element[χ, Reals]}
];

NewProjector[α_, χ_] = Flatten[{NewMatrix[α, χ] .NewMatrixC[α, χ]}, 1];


When I run,

{{#1, #2}, NewProjector[α, χ]} & @@@
OptimalPoints // MatrixForm


I don't get the desired list of matrices evaluated at points in the list optimal points

• matrix /. Thread[{a, b} -> #] & /@ list. Nov 1, 2016 at 15:32

A clean way to do this is to define a pure function and then Apply it to your list:

{{#1, #2}, {10 #1, 10 #2}} & @@@ list


{{{1, 2}, {10, 20}}, {{3, 4}, {30, 40}}, {{5, 6}, {50, 60}}, {{7, 8}, {70, 80}}, {{9, 10}, {90, 100}}}

Alternatively, you can create your own Function and Apply it to your list.

matrixFcn[a_, b_] := {{a, b}, {10 a, 10 b}}
matrixFcn @@@ list


The same output is generated.

• Hey. I have been trying such methods but to no avail. I have edited the post with the relevant codes for my problem. Nov 1, 2016 at 10:32
• I believe it works if you implement it as follows MatrixForm[#] & /@ {{#1, #2}, NewProjector[#1, #2]} & @@@ OptimalPoints. I think you'll also want to define your NewProjector function with the SetDelayed := command instead of the Set =` command, although it may not appear to make a difference at this point. @junaid-aftab Nov 1, 2016 at 12:06