MathGroup Archive 2006

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

Search the Archive

Re: NonlinearFit + Sums

I would suggest assigning the list of variable names to a symbol and using 
Total to do the summation in the model.  A shortened example using 5 x_i 
variables follows.

In[1]:= << Statistics`

In[2]:= xvect = Table[ToExpression[StringJoin["x", ToString[i]]], {i, 1, 5}]

Out[2]= {x1, x2, x3, x4, x5}

In[3]:= model=E^(mu)*Total[xvect]

Out[3]= E   (x1 + x2 + x3 + x4 + x5)

In[4]:= data = Table[Random[], {100}, {6}];

In[5]:= NonlinearFit[data, model, xvect, {mu}]

Out[5]= 0.19181 (x1 + x2 + x3 + x4 + x5)

Since E^(mu) was just a constant multiplier in the model sent, I factored 
it out in model above.  In general, if you have a model that is a sum of a 
function f of the individual variables, you could do something like the 

In[6]:= Total[ Map[f, xvect]]

Out[6]= f[x1] + f[x2] + f[x3] + f[x4] + f[x5]

For the example model sent, this would work like the following.

In[7]:= Total[ Map[E^(mu)*#&, xvect]]//InputForm

Out[7]//InputForm= E^mu*x1 + E^mu*x2 + E^mu*x3 + E^mu*x4 + E^mu*x5

Darren Glosemeyer
Wolfram Research

At 03:12 AM 8/18/2006 -0400, Lyta wrote:
>I want to do a mulitdimensional nonlinear fitting and I'm not sure how to 
>define the mathematica statement for that.
>I have a matrix "data" of dimensions 140x37 that contains 36 samples of 
>140 functions. The 37th column contains the resulting value of a mapping 
>of the type R36->R1. I want to calculate the parameter mu of a function 
>that integrates over the samples - i posted a simplified version of the 
>function below. My problem is, that I don't know what to write instead of 
>x_i. For the second x_ it should be something like {x1, x2, x3, x4, ..., 
>x36}. But the first x_i should be something like x[[i]] (this doesn't work 
>ofc). How do i assign the data to the sum?
>NonlinearFit[data, Sum[E^(mu)*x_i, {i, 1, 36}], x_i, {mu}]
>I hope you can help :-)

  • Prev by Date: RE: Need good reference for writing Stylesheets
  • Next by Date: Re: memory issues
  • Previous by thread: Re: NonlinearFit + Sums
  • Next by thread: Re: NonlinearFit + Sums