Pomax / BezierInfo-2

The development repo for the Primer on Bézier curves, https://pomax.github.io/bezierinfo
https://pomax.github.io/bezierinfo
Other
2.31k stars 289 forks source link

Gauss–Legendre quadrature #244

Open yzrmn opened 5 years ago

yzrmn commented 5 years ago

Hi,

  1. The weight formula (https://pomax.github.io/bezierinfo/legendre-gauss.html) has a little typo, it says: [P'_n(x))]^2 should be [P'_n(x)]^2 I guess.
  2. The Mathematica script has some weird output (with version 11.0 at least). N[Solve[LegendreP[n, x] == 0]] with n>5 gives imaginary parts which shouldn't be there. The output then is e.g.
    0.661209386466264513661399595019905347006448564395170070814526705852183496607\
    14310094428640374646145642988837163927514667955734677222538043817231980100933\
    67423918538864300079016299442625145884902455718821970386303223620117352321357\
    02218793618906974301231555871064213101703`256.150514997832 + 
    0``256.3301759876852*I

    Also the output format isn't really clear to me (the '256. and following that). However, you could fix the imaginary parts with NSolve[LegendreP[n, x] == 0, x, Reals, WorkingPrecision -> precision]

Greetings!

Pomax commented 5 years ago
  1. oh man, nice catch!
  2. those are Mathematica's number marks, and are used to indicate the floating point precision. In this case you're looking at 0.66[...] + 0 · i, which includes the imaginary part, but its factor is zero, so a Simplify etc. would end up printing the number with the imaginary part omitted.
yzrmn commented 5 years ago

The imaginary part quite small (10E-17), so I think it's a precision error. You won't get these with numeric solve. Regarding the number marks: Wouldn't it be better without them? :)