MathGroup Archive 2011

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

Search the Archive

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


data = Sort@
    Table[{x + RandomReal[.05], .5 + 2 x + RandomReal[.05]}, {x, 0,
      1, .1}];

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

0.448981 + 2.03847 x

Show[Plot[f@x, {x, 0, 1}], ListPlot@data]

or

Clear[f, x]
f[x_] := Evaluate@Fit[data, {1, x}, x]

f@x

0.480993 + 2.02164 x

Show[Plot[f@x, {x, 0, 1}], ListPlot@data]

Bobby

On Sat, 17 Sep 2011 05:25:53 -0500, Just A Stranger  
<forpeopleidontknow at gmail.com> wrote:

> Hello,
>
> 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. )
>
> My jerry rigged solution is to just execute Fit[ data, {1,x}, x] then  
> copy
> and past the output to define a function. But this tacky solution just  
> won't
> do :)
>
> Thank you for your help mathgroup.


-- 
DrMajorBob at yahoo.com




  • Prev by Date: Re: List Manipulation- Advanced beginner question
  • Next by Date: Re: Interactive settings for ParamPlot3D. Mesh not quite working.
  • Previous by thread: Making a function from the output of the Fit function.
  • Next by thread: Re: Making a function from the output of the Fit function.