[Date Index]
[Thread Index]
[Author Index]
Re: Making a function from the output of the Fit
*To*: mathgroup at smc.vnet.net
*Subject*: [mg121554] Re: Making a function from the output of the Fit
*From*: Daniel Lichtblau <danl at wolfram.com>
*Date*: Mon, 19 Sep 2011 07:07:05 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
----- Original Message -----
> From: "Just A Stranger" <forpeopleidontknow at gmail.com>
> To: mathgroup at smc.vnet.net
> Sent: Saturday, September 17, 2011 5:25:53 AM
> Subject: Making a function from the output of the Fit function.
> 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.
Might be easier to use FindFit.
In[49]:= data =
Table[{j, 3*j - 2}, {j, 20}] + RandomReal[{-.1, .1}, {20, 2}];
Now one can do
In[58]:= a + b*x /. FindFit[data, a + b*x, {a, b}, x]
Out[58]= -1.939582811115561 + 2.994503289542548 x
or
In[61]:= f[x_] = a + b*x /. FindFit[data, a + b*x, {a, b}, x]
Out[61]= -1.939582811115561 + 2.994503289542548 x
Many years ago I used the term "jerry rigged" in some in-house email. I was informed that it is not proper phraseology. It seems that "jury rig" and "jerry build" are quite different in meaning.
Several years after that incident, I noticed "jerry rigged" in a James Ellroy novel (White Jazz, I think it was). It seems that the term has entered the language as a crossover of sorts.
http://www.wordcourt.com/archives.php?show04-03-10
http://en.wikipedia.org/wiki/Jury_rig
http://www.answerbag.com/q_view/9245
Daniel Lichtblau
Wolfram Research
Prev by Date:
**Re: How create new style sheet- Mathematica 8**
Next by Date:
**Re: (x - 1) or (-1 + x)**
Previous by thread:
**Re: Plot axis length and size ratio (TwoPlot revive)**
Next by thread:
**Artistic impression of cloudy structures**
| |