Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5043

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

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Making a function from the output of the Fit function.
Date 2011-09-18 08:16 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j549ct$6bg$1@smc.vnet.net> (permalink)

Show all headers | View raw


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 comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Making a function from the output of the Fit function. Bill Rowe <readnews@sbcglobal.net> - 2011-09-18 08:16 +0000

csiph-web