4
$\begingroup$

I want to minimize a quadratic equation, but Mathematica does not solve it and only rewrites the solution. I wonder if there exist any way I can skip the computation by hand (I can solve it using Lagrangian method, but it is too long).

y = {y1, y2, y3}
yp = {yp1, yp2, yp3}
ypp = {ypp1, ypp2, ypp3}
Minimize[{(ypp1 - yp1)^2 + (ypp2 - yp2)^2 + (ypp3 - yp3)^2,  
           Mean[ypp] == 0 && Variance[ypp] == 1}, ypp]
$\endgroup$
5
  • $\begingroup$ I'd shift ypp and work out the new mean and variance, then use Minimize[{Total[(ypp)^2], Mean[ypp] == a, Simplify[Variance[ypp], Assumptions -> {ypp \[Element] Reals}] == b}, ypp, Reals]. $\endgroup$ Commented May 26, 2013 at 16:27
  • $\begingroup$ This is a repeat of this question: mathematica.stackexchange.com/questions/25845/… (last version in the answer) $\endgroup$
    – bill s
    Commented May 26, 2013 at 16:30
  • $\begingroup$ @bills You can vote to mark it as a duplicate. To do that (in case you don't know), click the "close" link > duplicate > enter the URL of the question. $\endgroup$
    – rm -rf
    Commented May 26, 2013 at 16:38
  • $\begingroup$ But the program above produces: Minimize::infeas: There are no values of {ypp1,ypp2,ypp3} for which the constraints 1/3 (ypp1+ypp2+ypp3)==0&&1/3 (ypp1^2+ypp2^2-ypp2 ypp3+ypp3^2-ypp1 (ypp2+ypp3))=={5,3,6,3} are satisfied and the objective function ypp1^2+ypp2^2+ypp3^2 is real valued. $\endgroup$
    – remo
    Commented May 26, 2013 at 16:42
  • $\begingroup$ @bill I believe there is a difference. yp1, yp2, and yp3 are symbolical here, contrary to v in your previous answer, and you don't get a result. $\endgroup$ Commented May 26, 2013 at 18:59

1 Answer 1

7
$\begingroup$

Firstly, variance uses Conjugate and that stumbles Minimize if ypp is symbolic. It can be mended with ComplexExpand. Secondly, evaluation is going for long. I supect it is due to many variants of relative positions of yp components. Setting the order explicitely, say yp1<yp2<yp3, gives the result:

y = {y1, y2, y3}
yp = {yp1, yp2, yp3}
ypp = {ypp1, ypp2, ypp3}
Minimize[{(ypp1 - yp1)^2 + (ypp2 - yp2)^2 + (ypp3 - yp3)^2, 
  Mean[ypp] == 0 && Variance[ypp] == 1 // ComplexExpand,  yp1 < yp2 < yp3}, ypp][[1, 1, 1, 1]]

$$ -\frac{4 \sqrt{\text{yp1}^2-\text{yp1} \text{yp2}-\text{yp1} \text{yp3}+\text{yp2}^2-\text{yp2} \text{yp3}+\text{yp3}^2}}{\sqrt{3}}+\text{yp1}^2+\text{yp2}^2+\text{yp3}^2+2 $$

$\endgroup$
2
  • $\begingroup$ Thanks a lot. It's really wonderful why such a simple question takes too long. $\endgroup$
    – remo
    Commented May 26, 2013 at 17:14
  • 1
    $\begingroup$ Nice trick. (+1) $\endgroup$ Commented May 26, 2013 at 19:01

Your Answer

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

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