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[10]:= f[3, 4, 5] Out[10]= 50 In[11]:= f[1, 2] Out[11]= 5 In[12]:= f[Sequence @@ Range[100]] Out[12]= 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[14]:= g[{1, 2}] Out[14]= 5 In[15]:= g[{3, 4, 5}] Out[15]= 50 In[16]:= g[Range[100]] Out[16]= 338350 But neither of these definitions use subscripts. I don't understand what you mean by "using subscripts" in this case.