0
$\begingroup$

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.2575422669022256316146199310035044964832661776461`15.*^-8, 
 1.57079639622776237973336943808513436304`15.
},
{
 6.5030057578379460133211810893852417847654553996698`15.*^-8, 
 1.57079630003754406967047630250839359743`15.
},
{
 0, 
 1.57079625737764823615943901490196281871`15.
}
}

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

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

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Hey. I have been trying such methods but to no avail. I have edited the post with the relevant codes for my problem. $\endgroup$ Nov 1, 2016 at 10:32
  • 1
    $\begingroup$ 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 $\endgroup$ Nov 1, 2016 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.