1

So I have function (FindCoefficients) that iterates through some values to find the maximum value for a function. It is much quicker to hold the non-linear values constant and do a find maximum for the linear coeffiecients then to do a non linear optimization for a complicated function.

This is the main line that I'm struggling with:

Do[Print[a , b, FindCoefficients[a, b]], {a, 1, 10, 1}, {b, 1, 10, 1}]

This gives me the output of

11{value of maximum, other info}

12{value of maximum, other info}

13{value of maximum, other info}

...

21{value of maximum, other info}

...

1010{value of maximum, other info}

Is there any way to sort my output from greatest to smallest, so I can easily pick out the maximum?

user64494
  • 26,149
  • 4
  • 27
  • 56
Pineapple
  • 111
  • 4
  • 3
    Use Table, not Do. Then you can Sort. You might find parts of this a useful reading: https://mathematica.stackexchange.com/q/134609/12 – Szabolcs Jun 03 '19 at 08:00

1 Answers1

2
SortBy[ Table[{a , b, FindCoefficients[a, b]} , {a, 1, 10, 1}, {b, 1, 10, 1}],{3}] 

sorts your Table according to the third column.

Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55