Approximating function derivatives
|
01-30-2024, 10:08 PM
(This post was last modified: 02-03-2024 09:04 PM by Albert Chan.)
Post: #23
|
|||
|
|||
RE: Approximating function derivatives
(01-30-2024 10:32 AM)Pekis Wrote: Well, that's more a Franken Central Finite Difference calculation : I like your setup better than the "proper" central difference fit. Spreadsheet is trivial to implement, copy *same* derivative formula to cells! Neighoring nearness of slopes is reassuring, gives us a heads up for typos. It is also easy to understand, slope of slope of slope ... Doing the calculation by fitting all points may not get much better. Bigger N-th difference is just noise ... garbage in, garbage out. (01-29-2024 02:59 AM)Paul Dale Wrote: Everyone needs to remember that numerical derivative algorithms are generally very unstable. As a reminder, function is ln, x0 = 3, h = 0.001/2, and the d(k)'s k-th differences. Code: P X Y d1 d2 d3 d4 d5 d6 I added mean of odd central difference to row center (P=0). This allowed direct computation of derivatives estimate. Source: Fundamentals of Numerical Analysis, 1975, Kellison, p. 152 (hD) = δ - 1/24*δ^3 + 3/640*δ^5 - ... What is nice is we can treat operator as expression, and get other derivatives! (hD)^2 = (δ - 1/24*δ^3 + 3/640*δ^5 - ...)^2 = δ^2 - 1/12*δ^4 + 1/90*δ^6 - ... (hD)^3 = (δ - 1/24*δ^3 + 3/640*δ^5 - ...)^3 = δ^3 - 1/8 * δ^5 + ... (hD)^4 = (δ - 1/24*δ^3 + 3/640*δ^5 - ...)^4 = δ^4 - 1/6 * δ^6 + ... (hD)^k f(0) is simply dot product of center row and corresponding coefficients. Code: D 1.0000E+00 -4.1667E-02 4.6875E-03 From size of numbers, (hD)^k ≈ δ^k, the others contributed very little. BTW, this is done in Lotus 123! I still retained muscle memory Correction: Fundaments of Numerical Analysis, p154 Wrote:However, there is a problem in using these central difference formulas to find the odd derivatives Author provided alternative formula, with mean operator µ (exactly what I did to fill missing holes) (hD) = µ*(δ - 1/6*δ^3 + 1/30*δ^5 - ...) Other odd derivatives can be built the same way (hD)^3 = (hD) * (hD)^2 = µ*(δ - 1/6*δ^3 + 1/30*δ^5 - ...) * (δ^2 - 1/12*δ^4 + 1/90*δ^6 - ...) = µ*(δ^3 - 1/4*δ^5 + ...) With these adjusted coefficients updated to spreadsheet, I get D¹ f(0): 0.3333333356 --> 0.3333333333, much better D³ f(0): 0.0740739692 --> 0.0740738582, slightly worse 3rd derivative getting worse because µδ^5 is garbage. With only µδ^3 term, D³ f(0) = 0.0740740802 This showed more points may make it worse. Less is more. (or, spread the points apart, with bigger h) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)