MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: polynomial fit.. prob with the help browser?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42484] Re: polynomial fit.. prob with the help browser?
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Thu, 10 Jul 2003 03:37:10 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 7/9/03 at 8:24 AM, ce.choa.phen.kee at philips.com wrote:

> I am just trying out the polynomialFit function but i encountered some 
> problems.. I applied the same thing found in mathematica help browser but 
> it gave me some strange output. Anyone can pls let me know if there's 
> anything wrong with the mathematica help browser?

> Load the polynomialfit package as: <<NumericalMathe'PolynomialFit'

> In[1]:= <<NumericalMathe'PolynomialFit'

> In[2]:= p=PolynomialFit[{1,4,9,16,25,36,49},3]
> Out[2]= FittingPolynomial[<>,3]
 
> In[3]:= Expand[p[x]]
> Out[3]= {54756., 57600., 60516., 63504., 66564., 69696., 72900., 76176., 
> 79524., 82944., 86436., 90000., 93636., 97344., 101124., 

I suppose you are trying to recover the coefficients of the polynomial fit by doing Expand[p[x]]. Fundamentally, the problem is polynomial fit isn't intended for this purpose

Specifically,

In[1]:=
<<NumericalMath`PolynomialFit`

In[2]:=
?PolynomialFit

In[2]:=
?PolynomialFit

"PolynomialFit[data, n] gives the least squares \
polynomial fit to data much as \
Fit[data,{1,x,x^2,...,x^n}, x] would do, except that the \
calculation is done in a way that is numerically stable \
and the result is given as a FittingPolynomial that is \
numerically stable.  Changing the form of the result is \
NOT advised for reasons of numerical stability."*
  Button[Moreâ?¦, ButtonData :> 
    "NumericalMath`PolynomialFit`", Active -> True, 
   ButtonStyle -> "AddOnsLink"]
 
 
 It is possible in this case to recover the exact polynomial as shown by
 
 In[3]:=
p=PolynomialFit[{1,4,9,16,25,36,49},3];

In[4]:=
Rationalize@Chop[p[x]]//Expand

Out[4]=
x^2

What I did was use Chop to force all small reals to zero and Rationalize to find the nearest exact coefficients befor doing the expansion. Simply by looking at the original problem it is easy to see the vector is x^2. And since you used a hogher order polynomial to fit the terms, you should expect a numerical technique like PolynomialFit to result in some small coefficients. That is why I expected the Chop and Rationalize to work as they did. 

But in general you won't have this information and the Chop and Rationalize process I've used here will not necessary result in a correct solution.


  • Prev by Date: help visualizing discontinous function
  • Next by Date: Evaluation and replacement?
  • Previous by thread: Re: polynomial fit.. prob with the help browser?
  • Next by thread: LatticeReduce extension