Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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]] &}]

plot

share|improve this answer
    
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 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}]
share|improve this answer
    
Thanks santosh - I guess I didn't frame my question well enough for you to interpret what I was after. –  CrustyNoodle Jan 22 at 22:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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