Post Reply 
(42S) Function Table
02-18-2019, 05:04 AM
Post: #1
(42S) Function Table
The program FTAB uses the function defined in FX, with variable “X” to generate a 2 column matrix of f(X). The matrix is stored in variable MATS. The program ends with MATS in edit mode, so you see all the points generated. Use the soft key [ → ] to view the entries.

Setting up FX

To set up the function FX, the program needs to be in the following format:
Code:

00 {nnn-Byte Prgm}
01 LBL “FX”
02 MVAR “X”
03 f(X) starts here, use RCL “X” for X

nn-1 RTN
nn END

HP 42S Program FTAB
HP 42S, DM 42, Free42
Code:

00 { 99-Byte Prgm }
01▸LBL "FTAB"
02 "X Start:"
03 PROMPT
04 STO 01
05 "X Step:"
06 PROMPT
07 STO 02
08 "# Steps:"
09 PROMPT
10 STO 03
11 1
12 -
13 1ᴇ3
14 ÷
15 STO 04
16 RCL 03
17 2
18 DIM "MATF"
19 INDEX "MATF"
20▸LBL 00
21 RCL 01
22 RCL 04
23 IP
24 RCL× 02
25 +
26 STO "X"
27 STOEL
28 J+
29 XEQ "FX"
30 STOEL
31 J-
32 I+
33 ISG 04
34 GTO 00
35 EDITN "MATF"
36 .END.

Example

f(x) = x^2 * e^x

FX:
Code:

00 { 18-Byte Prgm }
01▸LBL "FX"
02 MVAR "X"
03 RCL "X"
04 ENTER
05 X↑2
06 X<>Y
07 E↑X
08 ×
09 RTN
10 .END.


Input:
X Start: 0
X Step: 0.5
# Steps: 10

Result Matrix MATS:
Code:

MATF=    [ 10x2 Matrix ]
1:1=              0.0000
1:2=              0.0000
2:1=              0.1000
2:2=              0.0111
3:1=              0.2000
3:2=              0.0489
4:1=              0.3000
4:2=              0.1215
5:1=              0.4000
5:2=              0.2387
6:1=              0.5000
6:2=              0.4122
7:1=              0.6000
7:2=              0.6560
8:1=              0.7000
8:2=              0.9867
9:1=              0.8000
9:2=              1.4243
10:1=             0.9000
10:2=             1.9923

Link: https://edspi31415.blogspot.com/2019/02/...table.html
Visit this user's website Find all posts by this user
Quote this message in a reply
02-21-2019, 08:41 AM (This post was last modified: 02-21-2019 08:43 AM by ijabbott.)
Post: #2
RE: (42S) Function Table
Hi Eddie,

X Step should be 0.1 for the results you showed.

Also, I don't think RTN is necessary when it precedes END.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
02-21-2019, 11:57 AM
Post: #3
RE: (42S) Function Table
We can GROW the matrix:
Code:
00 { 45-Byte Prgm }
01▸LBL "FTAB"
02 STO 02
03 R↓
04 STO 01
05 R↓
06 STO 00
07 1
08 2
09 NEWMAT
10 EDIT
11 GROW
12▸LBL 00
13 RCL 00
14 →
15 RCL 00
16 XEQ "FX"
17 →
18 RCL 01
19 STO+ 00
20 DSE 02
21 GTO 00
22 DELR
23 EXITALL
24 END

(02-21-2019 08:41 AM)ijabbott Wrote:  Also, I don't think RTN is necessary when it precedes END.

In addition to that I don't see a reason to use MVAR.
Code:
00 { 10-Byte Prgm }
01▸LBL "FX"
02 X↑2
03 LASTX
04 E↑X
05 ×
06 END

The value of \(x\) can be found in register 00.

Example:

0 ENTER
0.1 ENTER
10
XEQ "FTAB"

x: [ 10×2 Matrix ]

This creates the same matrix as in Eddie's example:

0.0 0.0000
0.1 0.0111
0.2 0.0489
0.3 0.1215
0.4 0.2387
0.5 0.4122
0.6 0.6560
0.7 0.9867
0.8 1.4243
0.9 1.9923


Cheers
Thomas
Find all posts by this user
Quote this message in a reply
02-22-2019, 01:21 AM
Post: #4
RE: (42S) Function Table
It would be nice if there was a way to detect errors in the called FX function and store an error value in the matrix when it occurs. Flag 25 is close, but can only detect a single error. FTAB could do FS 25 before XEQ "FX" and test the flag afterwards. But if there are multiple places in FX where an error could occur, FX would need FC? 25, RET after each place where an error could occur.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
02-22-2019, 07:18 AM
Post: #5
RE: (42S) Function Table
(02-22-2019 01:21 AM)ijabbott Wrote:  But if there are multiple places in FX where an error could occur, FX would need FC? 25, RET after each place where an error could occur.

I'd rather delegate the error-handling to the function FX instead.
It could return specific strings like "Error", "+Infty", "-Infty" or "÷ by 0" in case of errors.
Code:
00 { 21-Byte Prgm }
01▸LBL "FX"
02 X=0?
03 GTO 00
04 1/X
05 RTN
06▸LBL 00
07 "÷ by 0"
08 ASTO ST X
09 END

The program FTAB just creates the table.

Example:

-1 ENTER
0.25 ENTER
9
XEQ "FTAB"

x: [ 9×2 Matrix ]

-1.0000 -1.0000
-0.7500 -1.3333
-0.5000 -2.0000
-0.2500 -4.0000
0.0000 "÷ by 0"
0.2500 4.0000
0.5000 2.0000
0.7500 1.3333
1.0000 1.0000

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
02-22-2019, 02:02 PM (This post was last modified: 02-22-2019 02:03 PM by Eddie W. Shore.)
Post: #6
RE: (42S) Function Table
I used FX and MVAR "X" because I wanted to FX to be versatile, should we need to use FX to calculate integrals.

I like the idea of using error messages in FX.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-22-2019, 08:58 PM
Post: #7
RE: (42S) Function Table
Here's a program for the HP-15C:
Code:
001-42,21,11 :   ▸LBL A
002-       2 :    2
003-42,23,11 :    DIM A
004-   43 33 :    R↑
005-   44  2 :    STO 2
006-   43 33 :    R↑
007-   44  3 :    STO 3
008-42,16, 1 :    MATRIX 1
009-42,21, 0 :   ▸LBL 0
010-   45  2 :    RCL 2
011-   45  3 :    RCL 3
012-44,40, 2 :    STO+ 2
013-      33 :    R↓
014-ᵘ  44 11 :    USER STO A
015-   32 15 :    GSB E
016-ᵘ  44 11 :    USER STO A
017-   22  0 :    GTO 0
018-45,16,11 :    RCL MATRIX A
019-   43 32 :    RTN
Make sure that lines 015 and 017 are inserted in USER mode.

The function \(f(x)=x^2 e^x\) is implemented here:
Code:
020-42,21,15 :   ▸LBL E
021-   43 11 :    x²
022-   43 36 :    LSTx
023-      12 :    eˣ
024-      20 :    ×
025-   43 32 :    RTN

Example:

0 ENTER
0.1 ENTER
10
A

A      10  2

The entries can be displayed by repeatedly running RCL A in USER mode.
For a moment the corresponding index will be flashed:

RCL A
A   1,1
0.0000

RCL A
A   1,2
0.0000

RCL A
A   2,1
0.1000

RCL A
A   2,2
0.0111

RCL A
A   3,1
0.2000

RCL A
A   3,2
0.0489



RCL A
A   9,1
0.8000

RCL A
A   9,2
1.4243

RCL A
A  10,1
0.9000

RCL A
A  10,2
1.9923

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 




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