I was trying to minimize a quartic polyonomial equation with a constraint using Mathematica but I got some conflicting results and I wanted to ask to you. Am I making a conceptual mistake or a coding mistake?
First I wanted to minimize using the Minimize function:
Minimize[pol1[1.9, 0.1],
c0r^2 + c0i^2 + c1r^2 + c1i^2 == 1, {c0r, c0i, c1r, c1i}];
As you can see the function called pol1 and the constraint is a unit sphere. Function is a quartic polynomial with funny coefficients:
Chop[N[pol1[1.9, 0.1]]]
2.23232 c0i^2 - 0.0995481 c0i^4 + 2.23232 c0r^2 -
0.199096 c0i^2 c0r^2 - 0.0995481 c0r^4 - 0.433493 c0i c1i +
0.126205 c0i^3 c1i + 2.07557 c0r c1i - 1.69557 c0i^2 c0r c1i +
0.126205 c0i c0r^2 c1i - 1.69557 c0r^3 c1i + 7.66189 c1i^2 -
0.763494 c0i^2 c1i^2 + 1.0748 c0i c0r c1i^2 - 7.94349 c0r^2 c1i^2 +
0.458615 c0i c1i^3 - 6.16151 c0r c1i^3 - 1.31455 c1i^4 -
2.07557 c0i c1r + 1.69557 c0i^3 c1r - 0.433493 c0r c1r +
0.126205 c0i^2 c0r c1r + 1.69557 c0i c0r^2 c1r +
0.126205 c0r^3 c1r - 1.0748 c0i^2 c1i c1r + 14.36 c0i c0r c1i c1r +
1.0748 c0r^2 c1i c1r + 6.16151 c0i c1i^2 c1r +
0.458615 c0r c1i^2 c1r + 7.66189 c1r^2 - 7.94349 c0i^2 c1r^2 -
1.0748 c0i c0r c1r^2 - 0.763494 c0r^2 c1r^2 +
0.458615 c0i c1i c1r^2 - 6.16151 c0r c1i c1r^2 -
2.6291 c1i^2 c1r^2 + 6.16151 c0i c1r^3 + 0.458615 c0r c1r^3 -
1.31455 c1r^4
It gave me a real solution.
But then I thought maybe I should do it in the proper way: use Lagrange multiplier method, take derivatives with respect to each parameters, solve the equations and then find the solution that has the global minimum:
eqs = pol1[1.9, 0.1] + \[Mu]*(c0r^2 + c0i^2 + c1r^2 + c1i^2 - 1)
eq1 = N[D[eqs, c0r]];
eq2 = N[D[eqs, c0i]];
eq3 = N[D[eqs, c1r]];
eq4 = N[D[eqs, c1i]];
eq5 = N[D[eqs, \[Mu]]];
NSolve[eq1 == 0 && eq2 == 0 && eq3 == 0 && eq4 == 0 && eq5 == 0, {c0r,
c0i, c1r, c1i, \[Mu]}]
Now this second method doesn't even return a real solution set. Where is the mistake?
I will be grateful if you help.
Mathematica version 11.01.0
pol1[...]
$\endgroup$NMinimize
and `Method->"DifferentialEvolution". $\endgroup$Minimize
, have trouble with approximate numbers (floats) -- and you've only given 6 of the 16 digits of each coefficient, although those rounding errors do not seem numerically significant here. You can improve the result converting them to arbitrary precision numbers:Minimize[SetPrecision[poly, 16], c0r^2 + c0i^2 + c1r^2 + c1i^2 == 1, {c0r, c0i, c1r, c1i}]
yields1.55
(in V11.3). [Aside from giving the exact polynomial you used, it would be considerate to others to indicate in the question why you ask about 1.97153.] $\endgroup$