TransWikia.com

RegionPlot of the Maximum of a function

Mathematica Asked on May 21, 2021

For the function fun[a_, b_, x_, y_] = Sin[a x] Cos[b y] (a x + b y);corresponding to $x$ and $y$, I need a RegionPlot showing the maximum of function $fun[a, b, x, y]>0.5$ such that the maximization is carried over $a,bin [0,1000]$.

A failed attempt: RegionPlot[{NMaximize[ fun[a, b, x, y] > 0.5, {a, 0, 1000}, {b, 0, 1000}]}, {x, 0, 2 [Pi]}, {y, 0, 2 [Pi]}]

One Answer

Inequalities are boolean expressions; they do not have maximums and minimums.

$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

Clear["Global`*"]

fun[a_, b_, x_, y_] = Sin[a x] Cos[b y] (a x + b y);

NMaximize[{fun[a, b, x, y], 0 <= a <= 1000, 0 <= b <= 1000, 0 <= x <= 2 Pi, 
   0 <= y <= 2 Pi}, {a, b, x, y}, WorkingPrecision -> 20] // N

(* {2797.59, {a -> 404.339, b -> 595.551, x -> 3.68672, y -> 2.19444}} *)

For nonlinear expressions, NMaximize generally only finds a local maximum.

Using a non-default Method provides a better result:

(sol = {#, NMaximize[{
          fun[a, b, x, y], 0 <= a <= 1000, 0 <= b <= 1000, 0 <= x <= 2 Pi, 
          0 <= y <= 2 Pi},
         {a, b, x, y},
         WorkingPrecision -> 20,
         Method -> #]} & /@
      {Automatic, "NelderMead", 
       "DifferentialEvolution", "SimulatedAnnealing"} //
     SortBy[#, #[[2, 1]] &] &) // N //
 Grid[#, Frame -> All] &

enter image description here

(param = sol[[4, 2, 2, 1 ;; 2]]) // N

(* {a -> 973.25, b -> 1000.} *)

Due to the complicated nature of the region's structure, this is quite slow.

RegionPlot[(fun[x, y, a, b] /. param) > 1/2,
 {x, 0, 2 Pi}, {y, 0, 2 Pi},
 PlotPoints -> 75,
 WorkingPrecision -> 20]

enter image description here

Using a much higher threshold.

RegionPlot[(fun[x, y, a, b] /. param) > 2500,
 {x, 0, 2 Pi}, {y, 0, 2 Pi},
 PlotPoints -> 75,
 WorkingPrecision -> 20]

enter image description here

Answered by Bob Hanlon on May 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP