Re: Making a function from the output of the Fit function.
- To: mathgroup at smc.vnet.net
- Subject: [mg121529] Re: Making a function from the output of the Fit function.
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 18 Sep 2011 04:13:39 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201109171025.GAA25998@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
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
- References:
- Making a function from the output of the Fit function.
- From: Just A Stranger <forpeopleidontknow@gmail.com>
- Making a function from the output of the Fit function.