Derivatives on HP 42S - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Derivatives on HP 42S (/thread-11249.html) Pages: 1 2 |
RE: Derivatives on HP 42S - lrdheat - 08-26-2018 04:47 PM Hi Thomas, The solver for dx=0 of some function fx, and then the running of fx to find f(x) of the extremum found by dx is quite successful. When I run dx for, say, pi/4 (let's be simple and use fx=sin x), I get ~0 instead of ~.707 Why is dx successful in solve, but not as a means to find dx of a specific x value? RE: Derivatives on HP 42S - Thomas Klemm - 08-26-2018 08:00 PM (08-26-2018 04:47 PM)lrdheat Wrote: Why is dx successful in solve, but not as a means to find dx of a specific x value? (08-21-2018 12:34 AM)Thomas Klemm Wrote: For a small discrete h, this can be approximated by To return an approximation for the derivative we have to divide \(\Im[f(x + ih)]\) by \(h\): Code: LBL "dF" With your example: Code: LBL "Fx" We can calculate the value of \(\frac{d}{dx}\sin(x)\) at \(x=1\): 1E-6 STO "h" 1 STO "x" XEQ "dF" x: 5.40302305868e-1 Compare this with \(\cos(1)\): 1 COS x: 5.40302305868e-1 Best regards Thomas RE: Derivatives on HP 42S - Albert Chan - 08-26-2018 08:39 PM (08-26-2018 04:47 PM)lrdheat Wrote: When I run dx for, say, pi/4 (let's be simple and use fx=sin x), I get ~0 instead of ~.707 my guess is you forget to divide by h: df(x) ~ Im((f(x + i*h)) / h Code: >>> from cmath import * RE: Derivatives on HP 42S - Albert Chan - 08-29-2018 01:52 PM A blog from the inventor of Complex Step Differentiation Algorithm. It had a fully worked out example, showing very stable and accurate estimates: https://blogs.mathworks.com/cleve/2013/10/14/complex-step-differentiation/ Real part of f(x + h*I) is also useful, for getting second derivative (involve subtraction): http://ancs.eng.buffalo.edu/pdf/ancs_papers/2006/complex_gnc06.pdf Since we already have the value of y = f(x + h*I) of approximate extremum x, we can improve it: Code: from cmath import * 2nd order x = 14.137167 3rd order x = 14.1371669412 Actual x = 14.137166942003920 ... |