Approximations for the Logarithm Function
|
12-02-2022, 07:42 PM
Post: #2
|
|||
|
|||
RE: Approximations for the Logarithm Function
We should compare sum with trapezoids vs squares, with same function evaluations (not intervals)
To simplify, we let t=s*x+1, to get integration limit from 0 to 1. RHS integral value is simply averaged height of its integrand. \(\displaystyle \ln(1+x) = \int_1^{1+x} \frac{1}{t}\,dt= \int_0^1 \frac{x}{x\,s + 1}\,ds \) For midpoint rule with 3 function evaluation, we trisect intervals. lua> function f(s) return x/(x*s+1) end lua> x = 0.2 lua> log1p(x) 0.18232155679395465 Trapezoidal Rule, and squares equivalent: lua> t1 = (f(0) + f(1))/2 lua> t2 = (t1 + f(1/2))/2 lua> t1, t2 0.18333333333333335 0.18257575757575759 lua> s1 = f(1/2) lua> s2 = (s1 + f(1/6) + f(5/6))/3 lua> s1, s2 0.18181818181818182 0.1822650467811758 Simpson 1/3 rule, and squares equivalent: lua> t2 + (t2-t1)/(4-1) -- weight = {1,4,1} / 6 0.18232323232323233 lua> s2 + (s2-s1)/(9-1) -- weight = {3,2,3} / 8 0.18232090490155006 Simpson 3/8 rule, and squares equivalent: lua> require'fun'() lua> function acc(s,x,y) return s+x*y end lua> function dot(x,y) return foldl(acc,0,zip(x,y)) end lua> dot({f(0/3),f(1/3),f(2/3),f(3/3)}, {1,3,3,1}) / 8 0.18232230392156865 lua> dot({f(1/8),f(3/8),f(5/8),f(7/8)}, {13,11,11,13}) / 48 0.18232121889089584 For ∫(1/x), sum with squares avoided edge bias, converge slightly better. |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Approximations for the Logarithm Function - Thomas Klemm - 12-02-2022, 09:33 AM
RE: Approximations for the Logarithm Function - Albert Chan - 12-02-2022 07:42 PM
|
User(s) browsing this thread: 1 Guest(s)