Post Reply 
(PC-12xx~14xx) qthsh Tanh-Sinh quadrature
03-29-2021, 02:28 AM (This post was last modified: 03-29-2021 05:00 PM by Albert Chan.)
Post: #4
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature
(03-29-2021 01:10 AM)robve Wrote:  
(03-28-2021 06:59 PM)Albert Chan Wrote:  >>> from mpmath import *
>>> f = lambda x: 1/sqrt(-ln(x))

The crash with this function does not happen in the C and BASIC versions I've worked on ...

∫(f(x), x=0..1) did not fail in Python mpmath either.

The problem is uf = lambda u: 6*u*(1-u) * f(u*u*(3-2*u))

∫(uf(u), u=0..1) will touch f(x=1) = ∞, much earlier than expected.

>>> utox = lambda u: u*u*(3-2*u)
>>> utox(0.9999999962747)
0.99999999999999989
>>> utox(0.9999999962748)
1.0

Update: we can fix uf(u), to never evaluate end-points.

>>> def uf(u):                   # u = 0 .. 1
...           x = u*u*(3-2*u)
...           if x==0 or x==1: return 0
...           return 6*u*(1-u) * f(x)
...
>>> quadts(uf, [0,1])
mpf('1.7724538508925098')

Trivia: if u slightly outside valid range, x will still be inside [0, 1]

utox(ε) = ε²*(3-2ε) ≥ 0, even if ε is negative
utox(1-ε) = (1-ε)²*(3-2*(1-ε)) = 1 - ε²*(3-2ε) ≤ 1, even if ε is negative
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature - Albert Chan - 03-29-2021 02:28 AM



User(s) browsing this thread: 6 Guest(s)