2
$\begingroup$

so i have a function $f(x,y)$ (sorry i cannot provide the whole function, it is long transfer matrix function) which i have plotted onto a 3D plot to identify the max values of the function. In addition the variables $x$ and $y$ are constrained $0<x<0.6$ and $0<y<7$

enter image description here

i am looking for a way to plot the $f(x,y)_{MAX}$ (the red region) as a 2D plot $x$ Vs $y$. And hopefully combine it with the 3D plot.

I have already tried to use NMaximize and MaxValue functions but have failed. Any help will be greatly appreciated.

Thank you in advance

$\endgroup$
  • $\begingroup$ This doesn't directly answer your question, but within Plot3D you could set MeshFunctions -> {#3&} to draw contours of constant z. This would help visualize better than just color. For the specific parametric curve of the maximum you could use Show[{Plot3D[<your plot here>] , ParametricPlot3D[<your maxima function here>]}]. $\endgroup$ – user7739 Jul 31 '18 at 14:51
  • $\begingroup$ Thank you for your reply, I didn't know about the ParametricPlot3D. Now I just need to find away to get the maxima function. $\endgroup$ – Jonathan Weerakkody Jul 31 '18 at 15:28
  • $\begingroup$ Realted 14863 $\endgroup$ – rhermans Aug 1 '18 at 11:16
2
$\begingroup$

Surface

pl1 = Plot3D[
  Exp[-2 (y - Sin[x])^2]
  , {x, 0, 2 π}
  , {y, -2, 2}
  , PlotRange -> All
  , MaxRecursion -> 8
  , PlotStyle -> Opacity[0.6]
  , ColorFunction -> "Rainbow"
  ]

Mathematica graphics

The maximum

pl2 = ParametricPlot3D[
  {x, Sin[x], 1}
  , {x, 0, 2 π}
  , PlotStyle -> Directive[Thick, Red]
  ]

Mathematica graphics

The bottom

pl3 = Plot[Sin[x], {x, 0, 2 π}, PlotStyle -> Black, 
  Filling -> Axis]

Mathematica graphics

Combined

Show[
 pl1,
 pl2,
 Graphics3D[
  pl3[[1]] /. {x_Real, y_Real} :> {x, y, 0}
  ]
 ]

Mathematica graphics

enter image description here

$\endgroup$
  • $\begingroup$ could you tell me how you obtained the maximum functions for the ParametricPlot3D ($f_x$, $f_y$, $f_z$)? $\endgroup$ – Jonathan Weerakkody Aug 1 '18 at 7:36
  • $\begingroup$ @JonathanWeerakkody In this case I constructed the 3D function to have that maximum. I would have calculated your case, but you didn't provide the code for the equation, and the question focuses in plotting. $\endgroup$ – rhermans Aug 1 '18 at 8:04
  • $\begingroup$ is there a generalized way to find this maximum function. The equation i am using is very long and tedious and it has many variable paramenters hard to represent here $\endgroup$ – Jonathan Weerakkody Aug 1 '18 at 11:06
  • $\begingroup$ @JonathanWeerakkody Then probably it could be done numerically for a limited number of points and then plot the InterpolatingFunction. The generalized way is to find where the first derivative is zero and the second derivative negative, but complicated functions and domains may need special considerations. $\endgroup$ – rhermans Aug 1 '18 at 11:08
  • $\begingroup$ thank you, i am actually trying that now. Is there anyway to get multiple points for the maximae using the Nmaximise option $\endgroup$ – Jonathan Weerakkody Aug 1 '18 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.