[VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
|
04-08-2019, 03:36 PM
(This post was last modified: 04-10-2019 02:41 AM by Albert Chan.)
Post: #30
|
|||
|
|||
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
I posted cin(x) puzzle to the Lua mailing list, and got an elegant solution from Egor Skriptunoff.
Taylor coefficients built on the fly, without any need for CAS. http://lua-users.org/lists/lua-l/2019-04/msg00063.html Below code modified a bit for speed, accuracy, and extended cin(x) for tin(x): Quote:local sin, asin = math.sin, math.asin lua> maclaurin_coefs = maclaurin_of_tin() lua> for i=50,125,25 do -- match post #28 Coefs : print(2*i+1, maclaurin_coefs(i)) : end 101 0.08337562280550574 151 388536047335.2163 201 6.555423874650777e+027 251 -3.536522049267692e+046 lua> function nest(f,x,n) for i=1,n do x=f(x);print(i, x) end end lua> nest(egor, 2.019, 2) -- egor = tin 1 0.9894569770589354 2 0.9012269893998129 lua> maclaurin_coefs = maclaurin_of_cin() lua> nest(egor, 2.019, 3) -- egor = cin 1 1.0269233186935764 2 0.9566289299961186 3 0.9012269893998129 lua> math.sin(2.019) 0.9012269893998126 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)