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

Posted 2 years ago
3247 Views
|
3 Replies
|
3 Total Likes
|
 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!
3 Replies
Sort By:
Posted 2 years ago
 I tried it as well. It appears to be a bug. I would report that to Support.Regards
 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 So the sorting is lexicographic?
 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