0

First question in this community (and rather new to the Mathematica world): thanks in advance for your help and sorry if the solution to the question is completely trivial!

I would like to have contours with 3D plots in the spirit of the question plotting 3d and contour (along with selected answer), with the addition of manipulate on a given parameter. Thus, for example, in line with the aforementioned previous question, how should I modify this piece of code to get the plot changing with variations wrt to $a$:

fun[x_, y_] := x + a y;
Show[Plot3D[fun[x, y], {x, -2, 2}, {y, -2, 3}, Mesh -> None, 
  PlotStyle -> Directive[Opacity[0.75], Specularity[White, 50]], 
  ColorFunction -> "Rainbow", PlotTheme -> "Detailed", 
  FaceGrids -> None], 
 SliceContourPlot3D[fun[x, y], 
  z == -1, {x, -2, 2}, {y, -2, 3}, {z, -1, 1}, 
  ColorFunction -> "Rainbow", Boxed -> False]]

I did try to put Manipulate in between Show and Plot3D (with related brackets added), but it didn't work out.

Kolmin
  • 135
  • 4
  • 1
    Manipulate[ Module[{fun}, fun[x_, y_] = x + a y; Show[Plot3D[fun[x, y], {x, -2, 2}, {y, -2, 3}, Mesh -> None, PlotStyle -> Directive[Opacity[0.75], Specularity[White, 50]], ColorFunction -> "Rainbow", PlotTheme -> "Detailed", FaceGrids -> None], SliceContourPlot3D[fun[x, y], z == -1, {x, -2, 2}, {y, -2, 3}, {z, -1, 1}, ColorFunction -> "Rainbow", Boxed -> False]]], {a, -2, 2}] – cvgmt Feb 18 '23 at 08:58
  • Thanks a lot, much appreciated! If you want to write it down as an answer, I will be happy to accept it. – Kolmin Feb 18 '23 at 09:21
  • Thanks, I post it as answer. – cvgmt Feb 18 '23 at 09:24

1 Answers1

1

Enclose the fun[x_,y_]=x+a*y by Module work.

Manipulate[
 Module[{fun}, fun[x_, y_] = x + a y; 
  Show[Plot3D[fun[x, y], {x, -2, 2}, {y, -2, 3}, Mesh -> None, 
    PlotStyle -> Directive[Opacity[0.75], Specularity[White, 50]], 
    ColorFunction -> "Rainbow", PlotTheme -> "Detailed", 
    FaceGrids -> None], 
   SliceContourPlot3D[fun[x, y], 
    z == -1, {x, -2, 2}, {y, -2, 3}, {z, -1, 1}, 
    ColorFunction -> "Rainbow", Boxed -> False]]], {a, -2, 2}]
cvgmt
  • 72,231
  • 4
  • 75
  • 133
  • I just wrote a follow up to this question here: https://mathematica.stackexchange.com/questions/280179/multiple-plots-with-same-colors-under-one-manipulate – Kolmin Feb 18 '23 at 10:02