Often times I find myself using unevaluated variables (i.e. they show up blue) as dummy variables in whatever I'm returning such that I can evaluate them as needed later on.
A simple example is as follows. Consider we have a function that returns a collection of monomials with 'x' as the independent variable.
getFns[n_] := Array[x^# &, n];
In this function, 'x' is simply a dummy (global) variable. Then suppose we have a function that returns a list of values corresponding to the list of monomials evaluated at specified coordinates:
useFns[fns_, coords_] := Array[fns[[#]] /. x -> coords &, Length[fns]];
Here is some sample input:
myFns = getFns[3]; (* {x, x^2, x^3} *)
myCoords = {1, 2, 3, 4};
useFns[myFns, myCoords]
which returns (as expected):
{{1, 2, 3, 4}, {1, 4, 9, 16}, {1, 8, 27, 64}}
The problem with this approach is that if the initial dummy variable is changed, it needs to be changed each time the list of functions is evaluated at specific points which can be tedious. Is there a better way to implement this?
xgetting a value accidentally, you can use\[FormalX], typed as ESC$xESC, which is Protected, so it's guaranteed not to have a value. – Szabolcs Apr 04 '13 at 01:49getFns[n]would becomegetFns[n,x], etc. – Szabolcs Apr 04 '13 at 01:52Rest[LinearAlgebra`VandermondeMatrix[Range[4]]]– J. M.'s missing motivation Apr 04 '13 at 02:28Outer[]might also be useful here:Outer[#1 @ #2 &, Table[(Evaluate[#^k]) &, {k, 3}], Range[4]]– J. M.'s missing motivation Apr 04 '13 at 02:31