lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tuesday, April 9, 2019, 5:55:08 PM EDT, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:


> I don't use smart methods like Newton's (mentioned by Dirk). 
> My implementation is dumb and straightforward. 
> I solve trivially constructed system of equations to find Tailor coefficients of din(). 
> (I simply substitute one Tailor series into another.)
> If n first coefficients are already known, the formula for the (n+1)-th one is not very 
> complex.
 
Thank you for the code.
Does not look dumb / straightforward to me !
Still don't understand what d table is used for ...

Anyway, I think I also did it ... uh, by guessing :-)
First 20 din(x) coefficients matched your version (ignoring rounding errors).

A bonus is that coefficients generation is almost twice as fast.

Using your code as template, just replace f() and maclaurin_of_din():

local function f(coef)
    local r = 0
    for j = 1, #c do
        r = r + coef[j] * g(2*j+1, #c+1-j, c)
    end
    return r
end
 
local d2 = {[0] = 1}

function maclaurin_of_din(k) 
    for n = #c + 1, k do
         a = {}
         local r, r2, r3 = f(c), f(d), f(d2)
         s, a = -(2*n)*(2*n+1)*s
         local t = (1/s-r-r2-r3)/4 
         assert(t*t < 1) 
         c[n], d[n], d2[n] = t, r + 3*t, r2 + 2*t         
      end 
      return c[k] 
   end