Such as, if I have the expression: v = a + 2b
, I want to define v
as a function of a,b
like v[a_,b_] = a + 2b
.
We can do this way
v = a + 2b;
f[a_, b_] :=
Evaluate[v /. {a :> ToExpression[ToString[a]],
b :> ToExpression[ToString[b]]}];
and we can check that f[1,2]
to call function ‘f’ and give the result 5
.
More complex example see: Defining a function with parameters as variables.