MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Functions of Arrays


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


  • Prev by Date: A Question about Combinatorica
  • Next by Date: Re: Generating a list numnber in string format
  • Previous by thread: Functions of Arrays
  • Next by thread: Re: Functions of Arrays