Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5043 > unrolled thread
| Started by | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| First post | 2011-09-18 08:16 +0000 |
| Last post | 2011-09-18 08:16 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: Making a function from the output of the Fit function. Bill Rowe <readnews@sbcglobal.net> - 2011-09-18 08:16 +0000
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Date | 2011-09-18 08:16 +0000 |
| Subject | Re: Making a function from the output of the Fit function. |
| Message-ID | <j549ct$6bg$1@smc.vnet.net> |
On 9/17/11 at 6:25 AM, forpeopleidontknow@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
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web