# Selection of the position of the variable

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[], Re[#1[]]}& /@ list1;
listIm = {#1[], -Im[#1[]]}& /@ 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?

• 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}]}] Apr 22, 2014 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) Apr 22, 2014 at 12:38
• Instead of #1 I used a. What other difference is between my try and your intent? Apr 22, 2014 at 12:44
• Yes but how can I use the Map (or &/@) with this formulation? Apr 22, 2014 at 13:15

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[], Re[#1[]]} & /@ list1;
listIm = {#1[], -Im[#1[]]} & /@ 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?)

• Yes that's it! Thank you very much Apr 22, 2014 at 16:44