MathGroup Archive 2012

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

Search the Archive

Re: Working with indefinite number of variables


How about 

sum[x_, n_] := Sum[i*x[[i]], {i, 1, n}]

As long as the x you provide has less than or equal to n parts, it will work.

In[27]:= x = {a, "hello", \[Pi], 17}

Out[27]= {a, "hello", \[Pi], 17}

In[28]:= sum[x, 3]

Out[28]= 2 "hello" + a + 3 \[Pi]



  • Prev by Date: Re: How to use FindMaximum with a parameter passed to NDSolve??
  • Next by Date: Terrible unit trouble in Mathematic 9
  • Previous by thread: Re: Working with indefinite number of variables
  • Next by thread: how to define step size in FindMinimum