Thanks in advance for any assistance you may be able to provide. I'm new to Mathematica and running into issues creating a usable function from the code seen below. For context, all of this code works as intended, outside of the implementation of the pure function itself (see last 2-3 lines):
ClearAll["Global`*"]
n = 2;
Do[θpsi[i] = RandomReal[π/2], {i, 1, (2^n) - 1}];
Do[ϕpsi[i] = RandomReal[2 π], {i, 1, (2^n) - 1}];
For[i = 0, i <= 2^n, i++,
Which[
i == 1, ψ[i] = {Cos[θpsi[i]]};,
i != 1 &&
i != 2^n, ψ[
i] = {Product[Sin[θpsi[j]], {j, 1, i - 1}]*
Cos[θpsi[i]]*E^(I*ϕpsi[i - 1])};,
i == 2^n , ψ[
i] = {Product[Sin[θpsi[j]], {j, 1, i - 1}]*E^(
I*ϕpsi[i - 1])};
](*Which*)
](*For*)
ψ = Array[ψ, 2^n]
ϕState[
i_] := {{Cos[Subscript[θ,
i]]}, {Sin[Subscript[θ, i]]*E^(I*Subscript[ϕ, i])}};
kronk = Fold[KroneckerProduct];
seperableStates = Table[ϕState[i], {i, 1, n}];
Φ = kronk[seperableStates];
x = (ConjugateTranspose[ψ].Φ)[[1, 1]]
(* Generate objective function *)
f = Function[{θ1, θ2, ϕ1, ϕ2}, x];
f[1, 2, 3, 4]
My goal is to take the result of x = (ConjugateTranspose[ψ].Φ)[[1, 1]]
and turn it into a user-friendly function that can be fed inputs, as seen on the last two lines.
Am I on the right track here? If not, how can I improve upon this code? I'm still trying to figure out Mathematica in general (recent convert from MATLAB), so any general feedback would be appreciated as well.
Cheers!