Post Reply 
(35S) 2nd order Derivative (at a point)
11-11-2020, 12:35 AM
Post: #4
RE: (35S) 2nd order Derivative (at a point)
(11-10-2020 11:23 PM)trojdor Wrote:  What would you suggest as a good example?

We wanted a test function with errors dependent on size of h.
For polynomials, use quartic or higher degree.

XCas> f(x) := x*(x^3 + 5*x^2 - 21*x)
XCas> expand(f(x+4))       → x^4+21*x^3+135*x^2+328*x+240

f(4) = 240
f'(4) = 328*1! = 328
f''(4) = 135*2! = 270

// Estimate f'(4), with different h's

XCas> (f(x+h) - f(x)) / h | x=4, h=1e-3             → 328.135021001
XCas> (f(x+h) - f(x)) / h | x=4, h=1e-6             → 328.000134999

XCas> (f(x+h) - f(x-h)) / (2h) | x=4, h=1e-3      → 328.000021
XCas> (f(x+h) - f(x-h)) / (2h) | x=4, h=1e-6      → 328.00000001

// Estimate f''(4), with different h's

XCas> t1 := (f(x+h) - 2*f(x) + f(x-h))/(h*h) | x=4, h=1e-1       → 270.02
XCas> t2 := (f(x+h) - 2*f(x) + f(x-h))/(h*h) | x=4, h=1e-2       → 270.0002
XCas> t3 := (f(x+h) - 2*f(x) + f(x-h))/(h*h) | x=4, h=1e-3       → 270.000002132

h=1e-3 is slightly too small. Without rounding errors, t3 = 270.000002 (exactly)

Richardson Extrapolation from t1, t2 gives excellent estimated for f''(4):

XCas> t2 + (t2-t1) / (100-1)       → 270.0
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-11-2020 12:35 AM



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