How do I use Map for a function with two arguments?
You can create a pure function that maps only on ratio
as follows:
Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True]
You will need the Evaluated -> True
option in order for Plot
to view the functions as several different ones and plot them in different colours.
You can also bypass having to use Map
by creating your function with the Listable
attribute. For example:
rp2[x_] := Function[{r}, 1000 x (r + 1)/(r + x), Listable]
Plot[rp2[x][ratios], {x, 0, 1}, Evaluated -> True]
This returns the same output as above, but automatically maps (threads) over lists.
This is a direct fulfilling of your attempts :
Plot[ rp[x, #] & /@ ratios, {x, 0, 1}]
rp[x, #] &
denotes a function depending on the second argument in rp
, while /@
is a shorthand for Map
, i.e rp[x, #] & /@ ratios
means Map[ rp[ x,#] &, ratios ]
.
Here is another way to plot your functions without Map
:
Plot[ Evaluate[ Table[ rp[x, a], {a, ratios}]], {x, 0, 10}]
Evaluate
serves here for plotting curves in various colors.
You can plot graphs of the functions as a family of curves in three dimensions using
ParametricPlot3D
.
ParametricPlot3D[ Evaluate[ Table[{x, a, rp[x, a]}, {a, ratios}]],
{x, 0, 10}, BoxRatios -> {10, 10, 5}]
Some things to think about:
rp[x_, r_] := 1000 x (r + 1)/(r + x)
rp[x, #] & /@ ratios
Outer[rp, {x}, ratios][[1]]
Table[rp[x, i], {i, ratios}]
Block[{rp},
rp[x, ratios] // Thread
]
And Formal Symbols (looks better in the Notebook):
ClearAll[rp]
rp[r_] := 1000 \[FormalX] (r + 1)/(r + \[FormalX])
Plot[rp /@ ratios, {\[FormalX], 0, 1}, Evaluated -> True]
And this (see Parameterized function and Currying in Mathematica):
ClearAll[rp]
rp[x_][r_] := 1000 x (r + 1)/(r + x)
Plot[rp[x] /@ ratios, {x, 0, 1}, Evaluated -> True]
Be sure to read this and this for an explanation of Evaluated -> True
.