Lets consider that I've this function:
fn = a*x^2 + b*x + c;
The idea here is to assign automatically the variables a
, b
, c
and x
to a function so it becomes something like that:
fn[x_,a_,b_,c_] := a*x^2 + b*x + c
In order to do this I've tried to extract the varibles from fn
using Variables
:
Sort@Variables@fn
{a, b, c, x}
Then in order to apply it to the function fn
I do the following:
fn1@Variables@fn /. List -> Sequence
fn1[a, b, c, x]
Questions:
- Is it possible to add the
Blank
s to the former expression in order to havefn1[a_,b_,c_,x_]
?
One of my fail attempt to do this was to use
Blank@#&/@Sort@Variables@fn
but it's obviously not working.
- One other point is that if you consider that you've found a way to automaticly have
fn1[a_,b_,c_,x_]
, how to assign the value offn
tofn1[a_,b_,c_,x_]
without having thefn1[a_,b_,c_,x_] is protected
message?
Function[{x1,x2...},body]
. And will be definitely simpler. $\endgroup$