1

I have a list of symbols that I have defined using

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

giving

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

 fVchamber[d__]:=Function[d,Vchamber]

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

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
user4667
  • 11
  • 1
  • 2
    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 – Szabolcs Nov 15 '12 at 20:06
  • This is just one form that I have. I have expressions that are more complicated. – user4667 Nov 15 '12 at 20:47

1 Answers1

2

This seems to work:

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

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

fVchamber[d__]:=...

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
tkott
  • 4,939
  • 25
  • 44