Post Reply 
(35S) 2nd order Derivative (at a point)
11-10-2020, 02:20 PM
Post: #2
RE: (35S) 2nd order Derivative (at a point)
(11-09-2020 09:51 PM)trojdor Wrote:  EXAMPLE
If f(x)= x^3 + 5*x^2 - 21*x
Calcuate f"(x) at x=4

This is a bad example to test effect of h on 2nd derivative estimate.

XCas> f(x) := horner([a4,a3,a2,a1],x)
XCas> simplify( (f(x+h) - 2*f(x) + f(x-h)) / (h*h) )       → 2*a3 + 6*a4*x

For cubics, central difference 2nd derivatives is independent of h.

XCas> f(x):= x^3 + 5*x^2 - 21*x
XCas> (f(x+h) - 2*f(x) + f(x-h)) / (h*h) | x=4, h=1000       → 34

BTW, for decimal calculator, we might get slightly better accuracy by splitting f(x):
(this avoids possible rounding errors of 2*f(x))

c = f(x)
f''(x) ≈ ((f(x+h) - c) - (c - f(x-h))) / (h*h)

Quote:Zuleta uses this simple (forward distancing) approximation of the first derivative:

f'(x)~ (f(x+h) - f(x)) / h (where h>0 : specifically, 1E-6 in his program)

(It's surprisingly efficient. Note that while D.Levy states that a centered differencing formula is more accurate,
in the real world testing I performed with a CD program I wrote, I could see no real benefit to replacing the Zuleta pgm.)

For fair comparison, let's try both ways for f'(4), with same h = 1E-3:

XCas> (f(x+h) - f(x)) / h | x=4, h=1E-3                → 67.017001
XCas> (f(x+h) - f(x-h)) / (2*h) | x=4, h=1E-3       → 67.000001

We can confirm all derivatives by expanding f(x+4):

XCas> expand(f(x+4))       → x^3 + 17*x^2 + 67*x + 60

f(4) = 60
f'(4) = 67*1! = 67
f''(4) = 17*2! = 34
f'''(4) = 1*3! = 6
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (35S) 2nd order Derivative (at a point) - Albert Chan - 11-10-2020 02:20 PM



User(s) browsing this thread: 1 Guest(s)