Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

Re: Re: errors in 3.0(beta) and 2.2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5657] Re: [mg5623] Re: [mg5604] errors in 3.0(beta) and 2.2
  • From: daiyanh at mindspring.com (萩原大太郎)
  • Date: Sat, 4 Jan 1997 22:56:50 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Sherman Reed さんが  9:04 PM 1/1/97 -0500ごろに
「[mg5623] Re: [mg5604] errors in 3.0(beta) and 2.2」の件で:
>At 06:59 AM 12/27/96 +0000, you wrote:
>>(* It is very easy to get completely wrong results
>>in both 2.2 and 3.0(beta) using one line examples.=20
>>The following example concerns LegendreP[10,10,x]=20
>>in 2.2 on a Mac, but I got similar results with
>>3.0(beta). I noticed the errors when using Plot[]
>>with LegendreP[10,10,Cos[t*Degree]]
>>       I would appreciate comments, workarounds etc.=20
>>Does the released version of 3.0 have these errors?
>>
>>$Version
>>Macintosh 2.2 (May 4, 1993)
>>
>>(* Notice LegendreP[10,10,x] is a simple polynomial=20
>>of degree 10 *)
>>
>>LegendreP[10,10,x]
>>                  2       4       6      8    10
>>654729075 (1 - 5 x  + 10 x  - 10 x  + 5 x  - x  )
>>
>>(*The following two results look reasonable *)
>>LegendreP[10,10,Cos[179*Degree]]//N
>>          -9
>>2.27155 10
>>LegendreP[10,10,Cos[t*Degree]]/.t->179.0//N
>>          -9
>>2.27155 10
>>
>>(* The next result is wrong *)
>>LegendreP[10,10,Cos[179.0*Degree]]//N
>>          8
>>1.02775 10
>>
>>(* All the following results are wrong *)
>>LegendreP[10,10,Cos[179.9999*Degree]]//N
>>           48
>>-2.68317 10
>>LegendreP[10,10,Cos[179.99999*Degree]]//N
>>          51
>>4.88061 10
>>LegendreP[10,10,Cos[179.999999*Degree]]//N
>>          57
>>4.87838 10
>>LegendreP[10,10,Cos[t*Degree]]/.t->179.999999//N
>>0
>>
>>
>Jonathan
>
>I got different but clearly erroneous answers
>using 3.0 on Win 95.
>
>I have included a workaround that I put together
>after looking at the form of LegendreP[10,10,x].
>It appears that my answers are consistent.
>
>I also plotted the function around Pi and found
>that the granularity is similar to the answers
>I got with my approximation.
>
>Looks like someone did the coding that did not
>appreciate how errors can propagate and/or a
>serious error exists in the coding.
>
>LegendreP[10,10,x](* 3.0 view *)
>\!\(\(-654729075\)\=20
>    \((\(-1\) + 5\ x\^2 - 10\ x\^4 + 10\ x\^6 - 5\ x\^8 + x\^10)\)\)
>reed[x_]:=3D-654729075*(-1+x^2*(5+x^2*(-10+x^2*
>                (10+x^2*(-5+x^2)))))(* s.c.reed view *)
>LegendreP[10,10,Cos[179*Degree]]//N
>\!\(\(-2.18068588186959289`*^-7\)\)
>reed[Cos[179*Degree]]//N
>\!\(\(-2.90758117582612385`*^-7\)\)
>LegendreP[10,10,Cos[t*Degree]]/.t->179.0//N
>-2.18069=D710\^-7
>reed[Cos[t*Degree]]/.t->179.0//N
>-2.90758=D710\^-7
>LegendreP[10,10,Cos[179.0*Degree]]//N
>1.31519=D710\^11
>reed[Cos[179.0*Degree]]//N
>-2.90758=D710\^-7
>LegendreP[10,10,Cos[179.9999*Degree]]//N
>7.8638=D710\^50
>reed[Cos[179.9999*Degree]]//N
>4.36137=D710\^-7
>LegendreP[10,10,Cos[179.99999*Degree]]//N
>-7.91843=D710\^60
>reed[Cos[179.99999*Degree]]//N
>1.45379=D710\^-7
>LegendreP[10,10,Cos[179.999999*Degree]]//N
>1.91079=D710\^72
>reed[Cos[179.999999*Degree]]//N
>1.45379=D710\^-7
>
>Hope this helps.
>
>Sherman C. Reed

Hello,

Comments:
1) It is pretty safe to say that this "anomaly" is inevitable in num. anal.
2) You can use Mark Sofroniou's Optimize package to convert the polynomial
   into a numerically more stable (and faster) one by using Horner command.

Workaround:
There is another way to do this, and it's probably numerically a safer way.
If the comp. time is less of a concern, then convert the num. args. into
rationals such as by the following:

Rationalize[Cos[179*Degree]//N,10^-19]  ==>>

  2782560513
-(----------).
  2782984375

And plug in this exact rational as the arg. to the polynomial function.
Do N[...] at the end.  Since the rational arg. is accurate to 10^-19,
the num. of significant digits in this case is

      | d LegendreP    dx     |
- Log | ----------- --------- | ~ 14,
      |     d x     LegendreP |

a loss of 5 digits or so.  Not too bad I guess.

There is yet another way.  This is to use N[...,digit_num] enclosing the
entire symbolic expressions.  Don't know which way is the best (or popular).
But I'm aware that there are complicated functions out there which can't be
eval'ed to rationals, though this particular example isn't one of them.
BTW, this method is one of Mma's most powerful features, powrful in that late
Kuiper worked his entire life for it, or so I'm told.

A Good One

Daitaro Hagihara



  • Prev by Date: Linux / Unix: 3D graphics->monochrome.
  • Next by Date: MMA 3.0 for win95/NT crippled?!
  • Previous by thread: Re: errors in 3.0(beta) and 2.2
  • Next by thread: Re: Mathematica on Windows95