I have a value that is calculated based on the matric multiplication of 3 matrices, a projection in a hilbert space really. I then take the trace of this to calculate the probability
probM1 = Tr[
Flatten[Map[KroneckerProduct @@ # &, {{IdentityMatrix[2], p1}}],
1].upF.Flatten[
Map[KroneckerProduct @@ # &, {{IdentityMatrix[2], p1}}], 1]];
The matrix p1 is a 2x2 matrix with parameters undefined that I am trying to minimize
p1 = KroneckerProduct[{Cos[θ], Exp[I ϕ]*Sin[θ]},
Conjugate[{Cos[θ], Exp[I ϕ]*Sin[θ]}]];
I am calling NMinimize as follows:
NMinimize[{probM1[θ, ϕ], {θ ∈
Reals, θ <= 2*π, ϕ ∈ Reals,
0 <= ϕ <= 2*π}}, {θ, ϕ}]
Now as you might guess, the issue I get is the following:
NMinimize::nnum: The function value (0.5 +2.53397*10^-49 I)[6.28319,5.22609] is not a number at {θ,ϕ} = {6.28319,5.22609}.
Ready a few posts, the problem seems to be with symbolic expression, and NumericQ seems to be a possible solution. However, it always seems to be called via an input to a created function, which I don't have here. Is there a way to utilize it just using the code I currently have, or will I need to specify a function for one of these 3 blocks?
I have tried
f[pro_?NumericQ] :=
Tr[Flatten[Map[KroneckerProduct @@ # &, {{IdentityMatrix[2], pro}}],
1].upF.Flatten[
Map[KroneckerProduct @@ # &, {{IdentityMatrix[2], pro}}], 1]]
NMinimize[{f[
p1], {θ ∈ Reals, θ <=
2*π, ϕ ∈ Reals,
0 <= ϕ <= 2*π}}, {θ, ϕ}]
But I get the same issue.
Edit:
Here is an example of upF
{{0.375, -0.225754 + i0.0998109,
0.125, -0.0752515 - i0.0998109}, {-0.225754 - i0.0998109,
0.375, -0.0752515 + i0.0998109,
0.125}, {0.125, -0.0752515 - i0.0998109,
0.125, -0.0752515 - i0.0998109}, {-0.0752515 + i0.0998109,
0.125, -0.0752515 + i0.0998109, 0.125}}
upF
? You preventf
from evaluating without a numeric argument; however,f
doesn't use any numeric techniques and isn't affected by this. TheNMinimize
expression is the numeric technique and that is what needs to be defined as a function with appropriate parameters and stopped from trying to evaluate unless the parameters have numeric values. $\endgroup$