       Re: Defining function with indexed variables

• To: mathgroup at smc.vnet.net
• Subject: [mg99344] Re: Defining function with indexed variables
• From: Bill Rowe <readnews at sbcglobal.net>
• Date: Sun, 3 May 2009 05:22:27 -0400 (EDT)

```On 5/2/09 at 5:58 AM, phhs80 at gmail.com (Paul Smith) wrote:

>How can one define the function

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

>using superscripts?

It isn't clear to me what you are trying to do here. If I wanted
a function that would compute the sum of squares for an
arbitrary number of arguments I would define it as:

f[x___] := Total[{x}^2]

with this definition I can do

In:= f[3, 4, 5]

Out= 50

In:= f[1, 2]

Out= 5

In:= f[Sequence @@ Range]

Out= 338350

But of course I can get the same result by defining this
function to work on a list. That is

g[x_List]:=Total[x^2]

In:= g[{1, 2}]

Out= 5

In:= g[{3, 4, 5}]

Out= 50

In:= g[Range]

Out= 338350

But neither of these definitions use subscripts. I don't
understand what you mean by "using subscripts" in this case.

```

• Prev by Date: Re: Inverse function
• Next by Date: Re: Can't apply Differencesto a SparseArray[]?
• Previous by thread: Re: Defining function with indexed variables
• Next by thread: Re: Defining function with indexed variables