Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: How to assign the result from NonlinearFit to a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70231] Re: How to assign the result from NonlinearFit to a function
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Sun, 8 Oct 2006 02:04:49 -0400 (EDT)

On 10/7/06 at 7:09 AM, PengYu.UT at gmail.com wrote:

>I have the following code. I want to assign the resulting function
>of NonlinearFit to function f. But it seems that it doesn't work.
>Would you please help me?

><< Statistics`NonlinearFit`

>data = {{1.0, 1.0, .126}, {2.0, 1.0, .219}, {1.0, 2.0, .076}, {2.0,
>2.0, .126}, {.1, .0, .186}};

>f[theta1_, theta2_,  theta3_] := NonlinearFit[data, theta1 theta3
>x1/(1 + theta1 x1 + theta2 \ x2), {x1, x2}, {theta1, theta2,
>theta3}]

Part of the problem you are having is you are defining the 
function f to take as arguments the parameters you are asking 
NonlinearFit to find. That is f cannot depend on the arguments 
you supply as Nonlinear fit will replace them with numerical 
values determined by the data.

Perhaps you want something like the following

In[23]:=
f[x_, y_] := Evaluate[NonlinearFit[data,
      theta1*theta3*(x1/(1 + theta1*x1 + theta2*x2)),
      {x1, x2}, {theta1, theta2, theta3}]] /.
    Thread[{x1, x2} -> {x, y}]

In[24]:=
f[x,y]

Out[24]=
(2.442770155675669*x)/(3.1315052420200065*x +
    15.159362112360792*y + 1)

In[25]:=
f[1,2]

Out[25]=
0.0709072

Note, the built in function FindFit does everything NonlinerFit 
does. So, this same result could be obtained as:

In[27]:=
g[x_, y_] := (theta1*theta3*x)/(theta1*x + theta2*y +
      1) /. Evaluate[FindFit[data, (theta1*theta3*x1)/
       (theta1*x1 + theta2*x2 + 1), {theta1, theta2,
       theta3}, {x1, x2}]]

In[28]:=
g[x,y]

Out[28]=
(2.442770155675669*x)/(3.1315052420200065*x +
    15.159362112360792*y + 1)

In[29]:=
g[1,2]

Out[29]=
0.0709072

--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Troubles with Integrate
  • Next by Date: Re: Problem with nested NIntegrate[]
  • Previous by thread: Re: How to assign the result from NonlinearFit to a function
  • Next by thread: Problem with nested NIntegrate[]