I have a list of symbols that I have defined using

d = Table[Symbol["d" <> ToString[i]], {i, 1, n}] 


d = {d1, d2, d3, d4, d5}

where n = 5 in this case. I use this as part of an argument to an interpolation, giving me

Vchamber = 0.111549 d1 - 0.101842 d2 + 0.857554 d3 - 1.09366 d4 + 2.24236 d5 

Now I want to define a function that gives something like

 fVchamber[d1_,d2_,d3_d4_,d5_] := 0.111549 d1 - 0.101842 d2 + 0.857554 d3 - 1.09366 d4 + 2.24236 d5 

Now, n is variable. Hence, the argument list is variable, as is the expression Vchamber. I was hoping that something like


would work but it doesn't. What am I doing wrong? I have looked for answers but I haven't found one yet.

  • 2
    $\begingroup$ Could you perhaps just work with lists instead of introducing those symbols? fVchamber[dlist_] := {0.1,0.2,0.3,0.4,0.5} . dlist $\endgroup$ – Szabolcs Nov 15 '12 at 20:06
  • $\begingroup$ This is just one form that I have. I have expressions that are more complicated. $\endgroup$ – user4667 Nov 15 '12 at 20:47

This seems to work:

fVchamber = Function[Evaluate@d, Evaluate@Vchamber]

So first, when you define a Function, you don't need a definition like


Second, Function apparently Holds the arguments, so you need to make sure they are evaluated. After the above definition, this seems to work:

In[10]:= fVchamber[0, 1, 0, 0, 0]
Out[10]= -0.101842
  • $\begingroup$ See, for example the example where they use a similar construct to set f equal to the pure function $\endgroup$ – tkott Nov 15 '12 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.