Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I defined a function funloglogplot to make a loglogplot of a function (function1) depending on several variables

funloglogplot[function1_, xmin_, xmax_, numpoints_] := 
  Module[{list1, listRe, listIm},
         list1 = {#1, function1[eps1, 1, #1, R1ideal, R2, ordre]}& /@ 
         logspace[xmin, xmax, numpoints];
         listRe = {#1[[1]], Re[#1[[2]]]}& /@ list1;
         listIm = {#1[[1]], -Im[#1[[2]]]}& /@ list1;
         ListLogLogPlot[{listRe, listIm}, Joined -> True] 

Nevertheless I would like to be able to choose the variables I am using for the plot (in this case I plot function1 as a function of its 3rd argument and I would like to be able to select the argument).
Can anyone see a solution?

share|improve this question
Something like this? f[x_, y_] := Sin[x/y]; funPlot[f_, var_] := Plot[f, var]; GraphicsRow[{funPlot[f[a, 1], {a, 1, 2}], funPlot[f[1, a], {a, 1, 2}]}] – Dr. belisarius Apr 22 '14 at 12:24
No. I would like to parametrize the argument of my function. It means to be able to put the #1 in an other place for example like this function1[eps1, 1, 1, #1, R2, ordre] (the #1 is at fourth position this time) – lambertmular Apr 22 '14 at 12:38
Instead of #1 I used a. What other difference is between my try and your intent? – Dr. belisarius Apr 22 '14 at 12:44
Yes but how can I use the Map (or &/@) with this formulation? – lambertmular Apr 22 '14 at 13:15
up vote 0 down vote accepted

You could pass a generic function f and the variable you want to plot it against and then use a replace inside the body of the Module. I am writing this without testing the code, but something along the lines of

funloglogplot[f_, {x_, xmin_, xmax_, numpoints_}] := Module[
  {list1, listRe, listIm}, 
  list1 = {#1, (f /. x -> #1)} & /@ logspace[xmin, xmax, numpoints];
  listRe = {#1[[1]], Re[#1[[2]]]} & /@ list1;
  listIm = {#1[[1]], -Im[#1[[2]]]} & /@ list1;
  ListLogLogPlot[{listRe, listIm}, Joined -> True]

Might do the trick. (You might have to tune the f /. x -> #1 assignment part. I remember it can be tricky).

You will then call your procedure specifying all parameters in your function except the variable one which you can call any name (x, for example, or z - you just have to be consistent) as in

funloglogplot[function1[eps1, 1, 1, z, R2, ordre], {z, 2, 6, 120}]

I hope this is pointing you in the right direction. It worked for me when I created my plotting routines (now, the problem is: am I recalling it correctly?)

share|improve this answer
Yes that's it! Thank you very much – lambertmular Apr 22 '14 at 16:44

Your Answer


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.