Re: evaluate f[{x,y,z}] when f[x,y,z] defined
- To: mathgroup at smc.vnet.net
- Subject: [mg103397] Re: evaluate f[{x,y,z}] when f[x,y,z] defined
- From: Peter Pein <petsie at dordos.net>
- Date: Sun, 20 Sep 2009 06:21:06 -0400 (EDT)
- References: <h9283i$lo6$1@smc.vnet.net>
Murray Eisenberg schrieb:
> I ought to know how to do this (simply) but don't, or at least don't
> recall how...
>
> Often I have a function of several variables defined, for example:
>
> f[x_, y_, z_] := Sqrt[x^2 + y^2 + z^2]
>
> And I have some list of numbers, e.g.:
>
> a = {4, 3, 2};
>
> How can I evaluate the following...
>
> f[a]
>
> .... without having to make a separate definition such as
>
> f[{x_, y_, z_}] := f[x, y,z]
>
> ?
>
There are some methods but I prefer the first one (In[3]):
In[1]:= f[x_, y_, z_] := Sqrt[x^2 + y^2 + z^2]
In[2]:= a = {4, 3, 2};
In[3]:= f @@ a
Out[3]= Sqrt[29]
In[4]:= f[Sequence @@ a]
Out[4]= Sqrt[29]
In[5]:= a /. List -> f
Out[5]= Sqrt[29]