Message Boards Message Boards

GROUPS:

ArgMax produces wrong result

Posted 23 days ago
247 Views
|
2 Replies
|
2 Total Likes
|

Hi,

ArgMax produces wrong result, if I use 17.0 as coefficient, and it produces correct result, if I use 17 as coefficient. Would be grateful for your advice. I use Mathematica 12.2.

ArgMax[-99 + 17.0* Sqrt[37 - 35 y] + 66 y, y]
ArgMax[-99 + 17* Sqrt[37 - 35 y] + 66 y, y] // N

produces:

NMaximize::nrnum: The function value -76.1928-31.3706 I is not a real number at {y} = {1.15444}.
0.405215
0.476622

The second result (0.476622) is correct, as confirmed by FindMaximum, by Solve[D[...]=0] and by Plot.

2 Replies

From help pages:

1.ArgMax is effectively equivalent to Last[Maximize]

  1. Maximize will return exact results if given exact input.

  2. If Maximize is given an expression containing approximate numbers, it automatically calls NMaximize.

Then:

 y /. NMaximize[-99 + 17.0*Sqrt[37 - 35 y] + 66 y, y][[2]](*wrong answer*)

 y /. NMaximize[-99 + 17.0*Sqrt[37 - 35 y] + 66 y, y, WorkingPrecision -> 20][[2]](*Correct answer,error messages*)

 y /. NMaximize[-99 + 17.0`20*Sqrt[37 - 35 y] + 66 y, y, 
    WorkingPrecision -> 20][[2]](*Correct answer,No error messages*)

 y /. NMaximize[-99 + SetPrecision[17, 20]*Sqrt[37 - 35 y] + 66 y, y, 
    WorkingPrecision -> 20][[2]](*Correct answer,No error messages*)

Summary:

ArgMax is exact symbolic solver. Will return exact results if given exact input.

Posted 22 days ago

Thanks, good point, useful to be aware of.

  • I note that increasing working precision in ArgMax doesn't solve the problem (the output is still off).

    ArgMax[-99 + 17.0*Sqrt[37 - 35 y] + 66 y, y, WorkingPrecision -> 200]
    
  • It seems it is advisable to avoid using ArgMax for numerical (non-symbolic) problems. Or, if must use it, to treat it as less stable numerical algorithm - it means to double-check the output by other methods.

  • FindMaximum works fine:

    FindMaximum[-99 + 17.0 Sqrt[37 - 35 y] + 66 y, y]
    
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