Second derivative with complex numbers
|
02-11-2021, 02:13 PM
Post: #5
|
|||
|
|||
RE: Second derivative with complex numbers
(02-11-2021 12:36 PM)Werner Wrote: It may avoid roundoff if you want high accuracy. Yes, but only with first derivative. (assumed im(f(x+hi)) does not hit with catastrophic cancellation) For second derivative, you still hit with subtraction cancellation errors. XCas> f(x) := x*(x^3+5*x^2-21*x) XCas> f1(x,h) := re((f(x+h)-f(x-h))/(2h)) // central difference 1st derivative XCas> f'(x) .- [f1(x,h), f1(x,h*i)] | x=4, h=1e-3 → [-2.10000508787e-05, 2.10000000607e-05] XCas> f'(x) .- [f1(x,h), f1(x,h*i)] | x=4, h=1e-6 → [-1.0320036381e-08, 2.09752215596e-11] XCas> f2(x,h) := re((f(x+h)-2*f(x)+f(x-h))/h^2) // central difference 2nd derivative XCas> f''(x) .- [f2(x,h), f2(x,h*i)] | x=4, h=1e-3 → [-2.13206476474e-06, 1.87539626495e-06] XCas> f''(x) .- [f2(x,h), f2(x,h*i)] | x=4, h=1e-6 → [0.0221821205923, 0.0506038300227] --- If |h| is not too small, we avoided catastrophic cancellation, error = O(h^2) We may take advantage of it, with h = ε*√i, which make h^2 purely imaginary. XCas> f'(x) - f1(x,h) | x=4, h=1e-3*√i → -2.44426701101e-12 XCas> f''(x) - f2(x,h) | x=4, h=1e-3*√i → -4.78621586808e-11 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Second derivative with complex numbers - peacecalc - 02-09-2021, 06:06 AM
RE: Second derivative with complex numbers - Albert Chan - 02-09-2021, 03:45 PM
RE: Second derivative with complex numbers - peacecalc - 02-11-2021, 09:49 AM
RE: Second derivative with complex numbers - Werner - 02-11-2021, 12:36 PM
RE: Second derivative with complex numbers - Albert Chan - 02-11-2021 02:13 PM
RE: Second derivative with complex numbers - Albert Chan - 02-12-2021, 04:55 PM
RE: Second derivative with complex numbers - Werner - 02-11-2021, 05:49 PM
RE: Second derivative with complex numbers - Werner - 02-11-2021, 07:01 PM
RE: Second derivative with complex numbers - Werner - 02-11-2021, 08:53 PM
RE: Second derivative with complex numbers - peacecalc - 02-13-2021, 09:00 AM
RE: Second derivative with complex numbers - Werner - 02-13-2021, 02:50 PM
|
User(s) browsing this thread: 1 Guest(s)