home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 19060 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  2.1 KB

  1. Path: sparky!uunet!wupost!crcnis1.unl.edu!tssi!backbone!backbone!wayne
  2. From: wayne@backbone.uucp (Wayne Schlitt)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: 9th order polynomial
  5. Date: Thu, 31 Dec 1992 04:44:30 GMT
  6. Organization: The Backbone Cabal
  7. Lines: 53
  8. Sender: wayne@backbone (Wayne Schlitt)
  9. Message-ID: <WAYNE.92Dec30224430@backbone.uucp>
  10. References: <1992Dec10.154522.15893@lambda.msfc.nasa.gov>
  11.     <1992Dec14.214016.149@ondec.lonestar.org>
  12.     <1992Dec29.103955.4864@spillman.uucp>
  13. NNTP-Posting-Host: helios.unl.edu
  14. In-Reply-To: tye@spillman.uucp's message of Tue, 29 Dec 1992 10: 39:55 GMT
  15.  
  16. In article <1992Dec29.103955.4864@spillman.uucp> tye@spillman.uucp (E. Tye McQueen) writes:
  17. > )
  18. > )  for (temp=d_src, accum=1.0, i=i_pow; i ; i>>=1, temp*=temp)
  19. > )    if (i&1) accum *= temp;
  20. > )  return(accum);
  21. > [...]
  22. > Note that the order in which you perform the operations to
  23. > compute a polynomial value can greatly affect the accuracy
  24. > of your calculation [ ... ]
  25. > It's been too long so I can't recall whether computing it as
  26. >     ((((a*x+b)*x+c)*x+d)*x+e)*x+f
  27. > was a particularly good or particularly bad method.  [ ... ]
  28. > Note that if  a*x  is almost equal to  -b  then this method
  29. > probably yields very poor results [ ... ]
  30.  
  31. if a*x aprox equals -b then a*x^n aprox equals -b*x^(n-1), so either
  32. way, you will loose gobs of precision.  The "missing" information is
  33. the least significant digits and they weren't stored anyway.  When you
  34. compute x^n and store it in a register, you are going to be missing
  35. _lots_ of least significant bits, where as if you multiply and
  36. accumulate, you don't loose as many if things cancel.
  37.  
  38. As an example, assume that we have 4 digits of accuracy in the
  39. floating point arithmetic:
  40.  
  41. x = 7.301
  42. a = 2.001
  43. b = -14.59
  44. c = 9.300
  45.  
  46. then a*x = 14.61 and a*x + b = .02000
  47.  
  48. the result of (a*x+b)*x+c = 9.446
  49.  
  50. the result of a*x^2+b*x+c = (2.001 * 53.30) + (-14.59 * 7.301) + 9.300 = 9.500
  51.  
  52. the real result should be: 9.440916601
  53.  
  54.  
  55.  
  56.  
  57. It's been a while since I studied this type of
  58. problem real hard too, but I think that the (a*x+b)*x+c method will
  59. typically give as good a result as you can get.
  60.  
  61.  
  62.  
  63. -wayne
  64.