(PC-12xx~14xx) qthsh Tanh-Sinh quadrature
|
04-08-2021, 03:32 AM
(This post was last modified: 04-08-2021 04:03 PM by Albert Chan.)
Post: #36
|
|||
|
|||
RE: (PC-12xx~14xx) qthsh Tanh-Sinh quadrature
qthsh version 2, using expm1() instead of exp(), for possibly more accuracy.
We can use below identity, to scale from x = expm1(a), y = expm1(b), to expm1(a+b) (x+1)*(y+1) - 1 = x*y + x + y Code: expm1 = require'mathx'.expm1 Redo example from https://www.hpmuseum.org/forum/thread-79...#pid145564 lua> function f(x) n=n+1; local y=expm1(x); return (x+x*y)/(1+y*y) end lua> function f01(t) local y=t*t-t; return f((2*t-1)/y) * (2*y+1)/(y*y) end lua> n = 0 lua> qthsh2(f01, 0, 1, 0) 0.8165947838638208 3.915835799526105e-009 lua> n 93 ∫(f(x), x=-inf .. inf) = ∫(f01(t), t=0 .. 1) = 3/8*log(2)*pi ≈ 0.8165947838638508 f(x) will decay to 0.0 for both ends, even if intermediate calculations overflowed. Thus, default 0.0 is appropriate here. Had we use previous point, we get this: lua> n = 0 lua> qthsh2(f01, 0, 1, 1) 0.8165983039584289 4.3106914389618785e-006 lua> n 178 Comment: too bad expm1 version make no difference. lua> qthsh(f01, 0, 1, 0) 0.816594783863821 3.915834575907313e-009 lua> qthsh(f01, 0, 1, 1) 0.8165983039584306 4.310691436990493e-006 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)