Re: Functions of Arrays

*To*: mathgroup at smc.vnet.net*Subject*: [mg102629] Re: [mg102590] Functions of Arrays*From*: DrMajorBob <btreat1 at austin.rr.com>*Date*: Mon, 17 Aug 2009 04:04:31 -0400 (EDT)*References*: <200908161039.GAA01145@smc.vnet.net>*Reply-to*: drmajorbob at bigfoot.com

f[x_?VectorQ] := x.x and then, for instance, f@Array[a, 5] a[1]^2 + a[2]^2 + a[3]^2 + a[4]^2 + a[5]^2 or f@Range[-2, 6] 96 Bobby On Sun, 16 Aug 2009 05:39:22 -0500, zak <u.gotzes at googlemail.com> wrote: > Functions can be defined via > > f[x1_, x2_] := x1^2 + x2^2 > > in Mathematica. > > > But how can I manage it to define a function depending on an array? > I would like to do something like > > Array[x,2] > f[x[1]_,x[2]_]:=x[1]^2+x[2]^2 > > because the length of the array varies in my application. > -- DrMajorBob at bigfoot.com

**References**:**Functions of Arrays***From:*zak <u.gotzes@googlemail.com>