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.

I would like to make easy to change the variable for which I am making a set of plots. Say I want to plot Sin, Tan, Cos and other functions of the same argument. To quickly switch from plotting it as function of x or y I wanted to use a "dummy" plot variable var and assing it to y or x depending on the need.

x = 1; var = y;
Plot[Sin[x*y], {var, 1, 2}]
Plot[Tan[x*y], {var, 1, 2}]
Plot[Cos[x*y], {var, 1, 2}]
Unset[{x, y, var}];

Unfortunately this doesn't quite works because var in the range specification {var,1,2} is not evaluated.

Any suggestions?

share|improve this question
2  
Evaluate@{var, 1, 2}... –  rasher May 5 at 7:53
    
great! it works, but what is the difference with respect to Evaluate[var] which was my trial before posting here? –  Roberto Franceschini May 5 at 10:16
1  
I can't check it but as far as I remember Evaluate works only on first level. –  Kuba May 5 at 13:37

1 Answer 1

You need to force evaluation of the x interval list:

x = 8; var = y;
Plot[Sin[x*y], Evaluate@{var, 1, 2}]
Plot[Tan[x*y], Evaluate@{var, 1, 2}]
Plot[Cos[x*y], Evaluate@{var, 1, 2}]
Unset[{x, y, var}];

plots

share|improve this answer

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.