Message Boards Message Boards

0
|
3613 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Summation indices inside of NMaximize

Posted 11 years ago

Hello!

Why don't the following commands produce equivalent results?

NMaximize[{10 *(-d[1] + d[2])^4* q[1, 2]^4 + (-d[1] + d[2])^2* 
    q[1, 2]^2* (4* q[1, 2]^2 + (q[1, 1] - q[2, 2])^2) - 
   6 *(d[1] - d[2])^3 *
    q[1, 2]^2 (q[1, 1] - q[2, 2]) (d[1] *q[1, 1] + d[2]* q[2, 2]) + 
   2 *(d[1] - d[2])^4* q[1, 2]^2 *(d[1]* q[1, 1] + d[2]* q[2, 2])^2, 
  d[1]^2 + d[2]^2 == 1, 
  q[1, 1]^2 + 2*q[1, 2]^2 + q[2, 2]^2 == 1}, {q[1, 1], q[1, 2], 
  q[2, 2], d[1], d[2]}]

and

NMaximize[{10 *(-x + y)^4 *b^4 + (-x + y)^2* 
    b^2 *(4* b^2 + (a - c)^2) - 
   6 (x - y)^3* b^2 (a - c)* (x* a + y *c) + 
   2 *(x - y)^4 *b^2*(x *a + y *c)^2, x^2 + y^2 == 1, 
  a^2 + 2*b^2 + c^2 == 1}, {a, b, c, x, y}]

For the first I get output :

NMaximize::nosat: Obtained solution does not satisfy the following constraints within Tolerance -> 0.001`: {1-d[1]^2-d[2]^2==0,1-q[1,1]^2-2 q[1,2,2]^2==0}. >>

For the second I get (correct) output:

{12.0002, {a -> 1.01851*10^-6, b -> -0.707108, c -> -3.9843*10^-7, 
  x -> -0.707108, y -> 0.70711}}

The first comes from using a summation index inside a NMaximize routine and I get the wrong result. When I replace the indexed variables with a,b,c,x,y then I get the correct results. I want to be able to vary the limit of summation for such functions and optimize them but it is not computing correctly.

Thanks!

POSTED BY: PW Laslo
4 Replies

The issue seems to appear when Method->"NelderMead" is used. Using "DifferentialEvolution" or "SimulatedAnnealing" works fine for the first example.

It is a bit strange since Method->"NelderMead" works fine on the second example. The variable names do influence the algebraic form given to NMaximize, but I didn't see any obvious evidence that was the issue. It might still be the case.

Anyway, long story short, I'd try using Method->"DifferentialEvolution".

POSTED BY: Sean Clarke
Posted 11 years ago

Sean changing the method works, thanks!

POSTED BY: PW Laslo
POSTED BY: David Reiss

There are essentially 2 related reasons why I think people see these behavior.

  1. You have not specified a value for the Method option for NMaximize. The "Method" option tells NMaximize which numerical method to use. Without it, NMaximize will try to select the numerical method that is most appropriate based on what it sees. In this case, it's pretty likely it's choosing different numerical methods and in one case the choice is better than the other. My advice is to try a number of them and see which work best for your kind of problem.

  2. As you may know, floating point numbers are sensitive. For example, the order in which a set of floating number is added together can matter greatly.

When adding some number of symbols together in the Wolfram Language, they will be sorted alphabetically. So c+b+a, becomes a+b+c. This means that if you're not careful, the names of your symbols can change the equations used by NMaximize. This could be a problem if the new equation is less numerically stable.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract