I am new to Mathematica and I am currently working on an optimization problem. The optimization function that I have easy to calculate for some assignment of variable but it is very difficult to calculate it explicitly. So, is there any function in Mathematica to optimize a function with some given constraint so that it does not need to calculate the function to be optimized explicitly.
Basically my function first takes the partial of a 4*4 matrix and then takes the log of that matrix, so I think it is getting very complicated to calculate the function explicitly. Main section of the code is:
comp[x_, y_] := x + I y;
mkvec2[x01_, x02_, x03_, x04_, y01_, y02_, y03_,
y04_] := {comp[x01, y01], comp[x02, y02], comp[x03, y03],
comp[x04, y04]};
densmat[v_] := ConjugateTranspose[{v}].{v};
densmat1[v_] := Simplify[Expand[ConjugateTranspose[v].v]];
pdensmat1[M_] := PartialTrace[M, {2, 2, 2, 2}, {2, 4}];
pdensmat2[M_] := PartialTrace[M, {2, 2}, {1}];
NEntropy[M_] := Expand[ Tr[-MatrixLog[M].M]/Log[2]];
veckraus[a_, b_] := KroneckerProduct[{a}, {b}];
Optm[ar_, br_, cr_, dr_, ai_, bi_, ci_, di_] :=
Re[NEntropy[pdensmat1[densmat1[Finvec[ar, br, cr, dr, ai, bi, ci, di]]]] - NEntropy[pdensmat2[densmat[mkvec2[Re[cr], 0, 0, Re[dr], Re[ci], 0, 0, Re[di]]]]]];
Optm[1/Sqrt[2], 1/Sqrt[2], 0.636944, 0, 0, 0, 0.770919, 0];
Optm[1/Sqrt[2], 1/Sqrt[2], 0.5, 0.7, 0.5, 0.6, 0.2, 0.6];
FindMaximum[{Optm[1/Sqrt[2], 1/Sqrt[2], cr, dr, 0, 0, ci, di], cr^2 + dr^2 + ci^2 + di^2 == 1}, {{cr, 0}, {dr, 0}, {ci, 0}, {di, 0}}]
Here the function "Optm" is the function to be optimized. It is very fast to calculate it for an assignment of variables as I have tried in 2nd and 3rd last line of the code but it is not working out when dealing with the "FindMaximum" problem.
I hope the question is clear, if not, let me know I will try to edit it.
NumericQ: see this User-defined functions, numerical approximation, and NumericQ – MarcoB May 20 '15 at 19:04PartialTraceandFinvec). – Daniel Lichtblau May 20 '15 at 19:08Clear[Optm]; Optm[ar_?NumericQ, br_NumericQ, cr_NumericQ, dr_NumericQ, ai_NumericQ, bi_NumericQ, ci_NumericQ, di_NumericQ] := ...– Daniel Lichtblau May 20 '15 at 19:15Optmmight not be evaluating "nicely" for symbolic input (input that is in terms of the variables and not numeric values). Forcing it to be undefined except for explicitly numeric input is a way to circumvent this. – Daniel Lichtblau May 20 '15 at 22:37Optmto "C" (checkCompilefunction documentation)? This will make it evaluate way faster (native code) and also will including the numeric constraints inherently. – Bichoy May 22 '15 at 05:55