(42S) Numerical Derivative - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (42S) Numerical Derivative (/thread-6538.html) |
(42S) Numerical Derivative - Eddie W. Shore - 07-11-2016 05:03 AM HP 42S: Numerical Derivative The program DERVX is based off my numerical derivative program for the HP 15C. To see the HP 15C program, click here: http://edspi31415.blogspot.com/2011/11/numerical-derivatives-in-part-9-we-will.html DERVX calculates numerical derivatives of f(x), given a small increment h. Generally, the smaller h is, the better the calculation. However with certain methods, if h is too small, the final result may be unexpected. This program uses a five-point formula: f'(x) ≈ (f(x - 2h) - 8 * f(x - h) + 8 * f(x + h) - f(x + 2h)) / (12h) The error is of the order of h^4. Source: Burden, Richard L. and J. Douglas Faires. "Numerical Analysis 8th Edition" Thomson Brooks/Cole Belton, CA 2005 Labels Used: Label DERVX: Main routine Label 00: f(X). This function starts with X on the X register. Numerical memory registers will be used, and they are the following: R00 = the numerical derivative R01 = X R02 = h Radians mode is automatically set. Code: HP 42S: Program DERVX How to run DERVX: 1. If desired, edit the function by [shift] [XEQ] (GTO) 00, [shift] [R/S] (PRGM). Remember you start with x in the X stack. End f(x) with RTN. 2. Input x, press [ENTER]. 3. Input h, press [XEQ] {DERVX}. Test 1: f(x) = x^2 + x*sin x, where x = π/4, h = 1E-5 The code for f(x) would look like this: Code: 39 LBL 00 π [ENTER] 4 [÷] 1 [E] -5 [XEQ] {DERVX} Result: 2.8333 Test 2: f(x) = x*e^x, where x = 1.75, h = 1E-5 The code for f(x) would look like this: Code: 39 LBL 00 1.75 [ENTER] 1 [E] -5 [XEQ] {DERVX} Result: 15.8252 RE: (42S) Numerical Derivative - Werner - 07-11-2016 06:39 AM if the function to be derived is defined in the complex plane, there is a much simpler, faster and more accurate way. The program below is my version of what was originally a 15C program by Valentin Albillo. Code: Usage: |