Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5053
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Making a function from the output of the Fit function. |
| Date | 2011-09-18 08:24 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j549r8$6ff$1@smc.vnet.net> (permalink) |
| References | <201109171025.GAA25998@smc.vnet.net> |
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@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@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Making a function from the output of the Fit function. DrMajorBob <btreat1@austin.rr.com> - 2011-09-18 08:24 +0000
csiph-web