Re: evaluate f[{x,y,z}] when f[x,y,z] defined
- To: mathgroup at smc.vnet.net
- Subject: [mg103407] Re: [mg103383] evaluate f[{x,y,z}] when f[x,y,z] defined
- From: Adriano Pascoletti <adriano.pascoletti at dimi.uniud.it>
- Date: Sun, 20 Sep 2009 06:24:10 -0400 (EDT)
- References: <200909190926.FAA22303@smc.vnet.net>
Apply changes the head of an expression. In your example you want to change
the head of a from List to f:
In[3]:=Apply[f,a]
Out[3]= Sqrt[29]
or, in infix notation,
In[4]:= f @@ a
Out[4]= Sqrt[29]
Adriano Pascoletti
2009/9/19 Murray Eisenberg <murray at math.umass.edu>
> 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]
>
> ?
>
> --
> Murray Eisenberg murray at math.umass.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower phone 413 549-1020 (H)
> University of Massachusetts 413 545-2859 (W)
> 710 North Pleasant Street fax 413 545-1801
> Amherst, MA 01003-9305
>
>
- References:
- evaluate f[{x,y,z}] when f[x,y,z] defined
- From: Murray Eisenberg <murray@math.umass.edu>
- evaluate f[{x,y,z}] when f[x,y,z] defined