Message Boards Message Boards

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

Why two optimization problems lead to different results by "MaximalBy"

Posted 4 years ago

Hello, friends Optimization 1:

MaximalBy[{{4.9375, {x -> -(3/4)}}, {2.0792, {x -> 2/Sqrt[
     3]}}}, First]

the result is: {{4.9375, {x -> -(3/4)}}}

Optimization 2:

MaximalBy[{{79/
   16, {x -> -(3/4)}}, {-1 + 16/(
    3 Sqrt[3]), {x -> 2/Sqrt[3]}}}, First]

the result is: {{-1 + 16/(3 Sqrt[3]), {x -> 2/Sqrt[3]}}}

Actually, they are the same optimization problems. Why? Thank you very much!

POSTED BY: Shaoyan Robert
3 Replies

I tried it as well. It appears to be a bug. I would report that to Support.

Regards

POSTED BY: Neil Singer
Posted 4 years ago

I think it might be a feature rather than a bug. Consider using FullForm:

Sort[{{4.9375, {x -> -(3/4)}}, {2.0792, {x -> 2/Sqrt[3]}}, {79/16, {x -> -(3/4)}}, 
      {-1 + 16/(3 Sqrt[3]), {x -> 2/Sqrt[3]}}}, Last] // FullForm

Sorted order of terms

So the sorting is lexicographic?

POSTED BY: Jim Baldwin

Jim,

You must be correct! If you do this, it works as "expected".

MaximalBy[{{79/16, {x -> -(3/4)}}, {-1 + 
    16/(3 Sqrt[3]), {x -> 2/Sqrt[3]}}}, N@*First]

(I made the function the Composition of N[] and First[]. so it treats the sort function numerically.

Good catch! However, this should be sent to support to improve the documentation and to add an example.

Regards,

Neil

POSTED BY: Neil Singer
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