0
$\begingroup$

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.

$\endgroup$
3
  • 1
    $\begingroup$ 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}] $\endgroup$
    – cvgmt
    Commented Feb 18, 2023 at 8:58
  • $\begingroup$ Thanks a lot, much appreciated! If you want to write it down as an answer, I will be happy to accept it. $\endgroup$
    – Kolmin
    Commented Feb 18, 2023 at 9:21
  • $\begingroup$ Thanks, I post it as answer. $\endgroup$
    – cvgmt
    Commented Feb 18, 2023 at 9:24

1 Answer 1

1
$\begingroup$

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}]
$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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