MathGroup Archive 2009

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

Search the Archive

Re: Defining function with indexed variables


Clear[f, x]

f[x__] := Module[{xl = Flatten[{x}]}, xl.xl]

f[Superscript[x, #] & /@ Range[3]] 

Superscript[x, 1]^2 + Superscript[x, 2]^2 + 
   Superscript[x, 3]^2

f[Superscript[x, #] & /@ Range[100]] == 
 f[Sequence @@ (Superscript[x, #] & /@ Range[100])]

True


Bob Hanlon

---- Paul Smith <phhs80 at gmail.com> wrote: 

=============
Dear All,

How can one define the function

f(x1,x2,...,x100) := x1^2 + x2^2 + ... + x100^2

using superscripts?

Thanks in advance,

Paul



  • Prev by Date: Re: Convex hull
  • Next by Date: Re: interactive 3d graphic in a palette?
  • Previous by thread: Re: Defining function with indexed variables
  • Next by thread: Re: Defining function with indexed variables