[DM15L] Analysis of a function f(x)

Contributed software for the DM10, DM11, DM12, DM15 and DM16 goes here.

Please prefix the subject of your post with the model of the calculator that your program is for.
Post Reply
rawi
Posts: 102
Joined: Sat Dec 28, 2019 4:50 am
Location: Bavaria, Germany

[DM15L] Analysis of a function f(x)

Post by rawi »

Code tags added by moderator for compactness.

This program helps in analyzing a function f(x) in a given area of x. The function should be defined and differentiable in the whole area. The program does the following tasks:
- Make a table of function values for sketching the curve
- Search for zero points
- Search for extrema
- Search for inflection points
- Compute the function value, the 1st and 2nd derivative at any given value for x
- Compute the length of the function curve between to given x-values

This is an improved version of an older program. The improvements are:
- For the computation of the first and the second derivative different increment values are used resulting in more precise results.
- Computation of function length is included.
- Code was shortened so that the length of the program did not increase much despite the improvements.
- Error in code was corrected
Many of these improvements are due to suggestions by Valentin Albillo whom I want to thank here.

Method:
The program approximates the derivative by adding and subtracting the small value d stored in Register I to x and evaluation the function. The derivative is estimated by (f(x+d)-f(x-d)/(2d).
The second derivative is approximated in a similar way by using additionally f(x) and a 10 times greater d to get numerical stable results.
Making the small value too big or too small delivers poor approximations. It is recommended to set it by .001. By experience the deviation then is about 1 unit in the fifth figure.

Use of registers: Registers 0-3 and I are used.

How to apply:
Preparation:
- Put in the function under LBL E. It must take the x-value from the X-register and return f(x) in X register.
- Put in a small number (recommendation: 0.001) in Register I.
Application:
1. To generate a table of function values:
- Starting point of x ENTER
- Ending point of X ENTER
- Step length x-values
- Press f A
Output:
- f(x) at starting point R/S
- f(x) at starting point + 1 * step length R/S
- f(x) at starting point + 2* step length R/S
….
Note: In the Y-register there is the x-value, in the X-register the value of f(x)
So at every step you can check the value of x by pressing x<>y 
2. To find a zero point of the function: Put in two estimates in the stack and press f SOLVE E (OK, this was easy)
3. To find an extremum: Put in two estimates in stack and press f SOLVE B. Program returns x value of extremum. To get f(x) at extremum press f E. If no extremum is found program returns “Error 8”.
4. To find an inflection point (i.e. an extremum of the first derivate) put in two estimates in stack and press f SOLVE C. Program returns x value of inflection point. To get f(x) at this point press f E. If no inflection point is found program returns “Error 8”.
5. To get the first derivative at a given x: Put in x in stack, press f B.
6. To get the second derivative of a given x: Put in x in stack, press f C.
7. To get the curve length of the function between two points: Put lower x in Y-register and upper x in X register and press f integration key D.

Example:
Function f(x) = (e^(-x²)+x²-5)/(sin(x)+2) in the area from -4 to 4.

Preparation:
The program for LBL E is listed below. 0.001 STO I.
1) Generate a table from x=-4 to x=4 with step width 1:
-4 ENTER 4 ENTER 1
f A: 3.9901 (This is the value of f(x) at -4. To check x press x<>y: -4)
R/S 2.1519 (=f(-3))
R/S -0.9000
R/S -3.1351
R/S -2.0000
R/S -1.2783
R/S -0.3374
R/S 1.8682
R/S 8.8482, which equals f(4).
2) Search for zero point between x=-3 and x=-2. -3 ENTER -2 f SOLVE E Result: -2.2346 (x-value of zero point). Search for zero point between x=2 and x=3: 2 ENTER 3 f SOLVE E -> 2,2346
3) Search for minimum between x=-2 and x=0. -2 ENTER 0 f SOLVE B -> -1.0796. To get f(x) at minimum press f E -> -3.1503
4) Search for inflection points:
-4 ENTER -3 f SOLVE C -> -3,5395. For f(x) at inflection point press f E -> 3.1531
-3 ENTER -1 f SOLVE C -> -1.9825. f E -> -0.9690
-1 ENTER 0 f SOLVE C -> -0.4898 f E -> -2.5978
0 ENTER 3 f SOLVE C -> 0.6831 f E -> -1.4846
5) Estimation the length of the function curve from -4 to 4:
-4 ENTER 4 f INTEGRATION KEY D -> 21.5315
6) Get first derivative at x=2: 2 f B -> 1.3015
7) Get second derivative at x=2: 2 f C -> 1.0425
Enjoy!
Raimund

Code: Select all

f LBL A		001 – 42,21,11
STO 0		002 – 44 0
R↓		003 – 33 
STO 2		004 – 44 2
x<>y		005 – 34 
STO 1		006 – 44 1
f LBL 0		007 – 42,21,0 
GSB E		008 – 32 15
RCL 1		009 – 45 1
x<>y		010 – 34 
R/S		011 – 31 
RCL 0		012 – 45 0
STO+1		013 – 44,40,1
RCL 2		014 – 45 2
RCL 1		015 – 45 1
g x<=y		016 – 43 10
GTO 0		017 – 22 0
g RTN		018 – 43 32
f LBL B		019 – 42,21,12		 
GSB 1		020 – 32 1
-		021 – 30 
RCL I		022 – 45 25
/		023 – 10 
2		024 – 2 
/		025 – 10  
g RTN		026 – 43 32
f LBL C		027 – 42,21,13
EEX		028 – 26 
1		029 – 1 
STOXI		030 – 44,20,25
R↓ 		031 – 33 
STO 1		032 – 44 1
GSB E		033 – 32 15
CHS		034 – 16 
STO 0		035 – 44 0
STO+0		036 – 44,40,0
RCL 1 		037 – 45 1
GSB 1		038 – 32 1
+		039 – 40
STO+0		040 – 44,40,0 
RCL I		041 – 45 25
STO/0		042 – 44 10,0 
STO/0		043 – 44,10,0
EEX		044 – 26 
1		045 – 1
STO/I		046 – 44,10,25 
RCL 0		047 – 45 0
g RTN		048 – 43 32
f LBL 1		049 – 42,21,1
STO 2		050 – 44 2
RCL I		051 – 45 25
-		052 – 30 
GSB E		053 – 32 15
STO 3		054 – 44 3
RCL 2		055 – 45 2
RCL I		056 – 45 25
+		057 – 40 
GSB E		058 – 32 15
RCL 3		059 – 45 3
g RTN		060 – 43 32
f LBL D		061 – 42,21,14
GSB B		062 – 32 12
g x²		063 – 43 11
1		064 – 1 
+		065 – 40 
SQRT		066 – 11 
g RTN		067 – 43 32
f LBL E		068 – 42,21,15
ENTER		069 – 36 
ENTER		070 – 36 
ENTER		071 – 36 
g x²		072 – 43 11
CHS		073 – 16
e^x		074 – 12 
x<>y		075 – 34 
g x²		076 – 43 11
+		077 – 40 
5		078 – 5 
-		079 – 30 
x<>y		080 – 34 
SIN		081 – 23 
2		082 – 2 
+		083 – 40 
/		084 – 10 
g RTN		085 – 43 32
Last edited by rawi on Tue Jun 09, 2020 3:28 pm, edited 3 times in total.
rawi
Posts: 102
Joined: Sat Dec 28, 2019 4:50 am
Location: Bavaria, Germany

Re: [DM15L] Analysis of a function f(x)

Post by rawi »

There is an error in the code. Command line 41 has to be "-" instead of "./."
Sorry for that.
Error is corrected
Last edited by rawi on Tue Jun 09, 2020 3:28 pm, edited 1 time in total.
rprosperi
Posts: 1703
Joined: Mon Apr 24, 2017 7:48 pm
Location: New York

Re: [DM15L] Analysis of a function f(x)

Post by rprosperi »

Why not just edit the original post to correct the error? You (as the author) can do that, but no one else can.

But I'd also add a note to the right, commenting that the line was corrected.

Also, please use code tags when posting long programs, to shorten the display and make copy/paste a bit easier.

Finally, thanks for sharing this.
--bob p

DM42: β00071 & 00282, DM41X: β00071 & 00656, DM10L: 071/100
toml_12953
Posts: 795
Joined: Wed May 03, 2017 7:46 pm
Location: Malone, NY USA

Re: [DM15L] Analysis of a function f(x)

Post by toml_12953 »

rawi wrote:
Fri Jun 05, 2020 10:16 pm
There is an error in the code. Command line 41 has to be "-" instead of "./."
Sorry for that.
Here's the corrected code, also illustrating code tags:

Code: Select all

01: f LBL A
02: STO 0
03: R↓
04: STO 2
05: x<>y
06: STO 1
07: f LBL 0
08: GSB E
09: RCL 1
10: x<>y
11: R/S
12: RCL 2
13: RCL 1
14: RCL 0
15: +
16: STO 1
17: x<=y?
18: GTO 0
19: g RTN
20: f LBL B
21: GSB 1
22: -
23: RCL I
24: 2
25: X
26: ÷
27: g RTN
28: f LBL C
29: STO 1
30: GSB E
31: STO 0
32: RCL 1
33: GSB 1
34: RCL 0
35: -
36: RCL I
37: ÷
38: x<>y
39: RCL 0
40: x<>y
41: -
42: RCL I
43: ÷
44: -
45: RCL I
46: ÷
47: g RTN
48: f LBL 1
49: STO 2
50: RCL I
51: +
52: GSB E
53: STO 3
54: RCL 2
55: RCL I
56: -
57: GSB E
58: RCL 3
59: x<>y
60: g RTN
61: f LBL E
62: ENTER
63: ENTER
64: ENTER
65: g x²
66: CHS
67: e^x
68: x<>y
69: g x²
70: +
71: 5
72: -
73: x<>y
74: SIN
75: 2
76: +
77: ÷
78: g RTN
Last edited by toml_12953 on Sat Jun 06, 2020 3:34 pm, edited 1 time in total.
Tom L

Some people call me inept but I'm as ept as anybody!
DM10L SN: 059/100
DM41X SN: 00023 (Beta)
DM41X SN: 00506 (Shipping)
DM42 SN: 00025 (Beta)
DM42 SN: 00221 (Shipping)
WP43 SN: 00025 (Prototype)
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: [DM15L] Analysis of a function f(x)

Post by Walter »

rawi wrote:
Fri Jun 05, 2020 10:16 pm
Command line 41 has to be "-" instead of "./."
Please allow me a dumb question: What function is "./." ? Do you mean "/" perhaps? If true, why don't you use it?
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
User avatar
akaTB
Posts: 794
Joined: Tue May 02, 2017 1:56 pm
Location: Milan, Italy

Re: [DM15L] Analysis of a function f(x)

Post by akaTB »

Or just ÷
Greetings,
    Massimo
ajcaton
-+×÷ left is right and right is wrong :twisted: Casted in gold
rawi
Posts: 102
Joined: Sat Dec 28, 2019 4:50 am
Location: Bavaria, Germany

Re: [DM15L] Analysis of a function f(x)

Post by rawi »

Dear all,

Thanks for your comments.

OK, perhaps I am a little bit too much a digital immigrant. I tried to edit the post but could not see a way to do so. It's quite easy at HPMuseum.org but I could not see the possibility here. Sorry. The sign ./. indeed stands for division. I could not find the sign of the calculator on my keyboard. So I tried to use something that is as near as possible to it. It is the same with x<>y which stands for exchange x- and y-register in stack.

Nevertheless I thought the program to be useful and wanted to share it.

Perhaps there is something like a instruction for use for people like me? ;-)

Best

Raimund
grsbanks
Posts: 1122
Joined: Tue Apr 25, 2017 11:23 am
Location: Preston, Lancs, UK
Contact:

Re: [DM15L] Analysis of a function f(x)

Post by grsbanks »

There's a bunch of icons at the top of each post (not each topic, each post). Let your mouse hover over each icon and you'll get a description of what each one does.
There are only 10 kinds of people in the world: those who understand binary and those who do not.
rawi
Posts: 102
Joined: Sat Dec 28, 2019 4:50 am
Location: Bavaria, Germany

Re: [DM15L] Analysis of a function f(x)

Post by rawi »

Hi,

I replaced the original version by an improved and extended version of the program.

Best

Raimund
Post Reply