# Dynamically change the variables plotted against in Plot3D

This question posed by @Cam is the closest I can find to my question but I feel that the answers don't really guide me in the way in which I'd like to proceed....

How do I dynamically change Manipulate controls?

Ultimately I'd like to be able to do this with Manipulate or Dynamic however for now I'd just be satisfied to get this working in a very manual way. If I can get it going manually then adding Dynamic will (hopefully) be the easy part.

I have a multivariate polynomial in (say) n variables but for simplification purposes let's call it 4 variables. I'd like to be able to use Plot3D to view the value of the function against two of the four variables but rather than specifying the variables explicitly, I'd like to be able to use some form of replacement rule to define which variables to plot against.

Conceptually speaking, I would like something like the following to work:

axes = {{w, 0, 20}, {x, -3, 3}, {y, -2, 2}, {z, -1, 1}};

w = 25;
x = -3;
y = -2;
z = 3;
Plot3D[Sin[w^(1/2) + x + y^2 + z^3], axes[[1]], axes[[3]]]


One of the important things here is that the axes variable contains both the variable to be plotted and its range.

Unless I'm mistaken, the responses in the post referenced above seemed to tackle a similar problem by substituting the variable names in the function to match the range specifications which I find confusing and hard to read, not to mention difficult to then sub in the correct ranges.

-

This could be a starting point : you select the two independent variables (with Ctlr) and then the function to be plotted and its ranges are updated. Finally all the information is passed to Plot3D.

You will have warnings if you change your choice of independent variables, but the plot will update.

    Manipulate[numValues = {w -> 25, x -> -3, y -> -2, z -> 3};
axes = {{w, 0, 20}, {x, -3, 3}, {y, -2, 2}, {z, -1, 1}};
vars = {w, x, y, z};
func = Sin[w^(1/2) + x + y^2 + z^3] /.
numValues[[Complement[Range[4], ind]]];
ranges = axes[[ind]];
Plot3D @@ {func, ranges[[1]], ranges[[2]], AxesLabel -> vars[[ind]]},
{{ind, {1, 2}, "Independent variables"}, ListPicker[#1, Range[4]] &}]


-
Thanks b.gatessucks, that gives me all the critical elements I need to move forward. I will dissect the code to understand it a little better (I've not used Complement before). Just one minor item... you need to remove the superfluous comma just before the AxisLabel directive otherwise it throws an error. – CrustyNoodle Jan 22 '14 at 22:42
Manipulate[Plot3D[Sin[w^(1/2) + x + y^2 + z^3],{w, 0, 20}, {x, -3, 3}], {y, -2, 2}, {z, -1, 1}]

-
Thanks santosh - I guess I didn't frame my question well enough for you to interpret what I was after. – CrustyNoodle Jan 22 '14 at 22:39
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.3340360224246979, "perplexity": 726.9940918603598}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-26/segments/1466783403502.46/warc/CC-MAIN-20160624155003-00027-ip-10-164-35-72.ec2.internal.warc.gz"}