Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Making a function from the output of the Fit function.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121514] Re: Making a function from the output of the Fit function.
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 18 Sep 2011 04:10:55 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 9/17/11 at 6:25 AM, forpeopleidontknow at gmail.com (Just A Stranger)
wrote:

>So I am trying to use the Fit ffunction to make another function.

>So I want to do something like this:

>f[x_] := Fit[ data, {1,x}, x]

>But I want f[x] to be the function for the line, a+bx. But as
>written above it does not have this result of course (I know it's
>because whatever gets passed is used as an argument for the fit
>function, so passing a number doesn't work, and passing a variable
>simply isn't what I want to do) So how can I use the fit function to
>get f[x_] :=  a+bx (where a and b are the appropriate constants. )

Use Set here instead of DelayedSet. DelayedSet is not optimum
here since every call to f will cause the fit parameters to be
recomputed. For only two parameters, this overhead probably
won't be significant. What you want can be done with Fit as follows:

In[24]:= data = RandomReal[1, 10];

In[25]:= f[x_] = Fit[data, {1, x}, x];

In[26]:= f[3]

Out[26]= 0.609511

In[27]:= f[y]

Out[27]= 0.017942 y+0.555686





  • Prev by Date: Re: String Deletion
  • Next by Date: Re: How create new style sheet- Mathematica 8
  • Previous by thread: Re: Making a function from the output of the Fit function.
  • Next by thread: Replace & Rationalize