Post Reply 
(HP71B) Bernoulli Polynomials
07-14-2023, 10:00 PM (This post was last modified: 07-17-2023 05:08 PM by Namir.)
Post: #1
(HP71B) Bernoulli Polynomials
Bernoulli Polynomials for HP-17B
================================

Memory Map
==========

N: Order (Integer)
N0:Last N (Integer)
X: X argument (Floating point)
B(): Bernoulli number array (Floating point)
B0: Bernoulli polynomial Bern(N,X) (Floating point)
I, J, K, M: Loop control variables (Integer)


Usage
=====

1) Press RUN key.
2) The program displays the prompt "N? ".
3) Enter N and press the END LINE key.
4) The program displays the prompt "X? ".
5) Enter X and press the END LINE key.
6) The program displays N, X, and the value of the Bernoulli polynomial.
7) Press the [f][+] keys and go to step 2.

Example
=======

Examples of B(N,X) are:

B(8,2) = 7.96666666751
B(6,3) = 198.023809524
B(4,4) = 143.966666667

Listing
=======

Code:

Line     Step
10    REM BERNOULLI POLYNOMIAL
20    DESTROY ALL
30    N0=0
40    INPUT "N? ";N
50    INPUT X? ";X
60    IF N=N0 THEN GOTO 100
70    DIM B(N)
80    CALL BERN(B(),N)
90    N0=N
100    B0=0
110    FOR K=0 TO N
120    B0=B0+FACT(N)/FACT(K)/FACT(N-K)*B(K)*X^(N-K)
130    NEXT K
140    DISP "B(";N;",";X;"=";B0
150    PAUSE
160    GOTO 40
170    END
180    SUB BERN(B(),N)
190    B(0)=1 @ B(1)=-.5
200    FOR M=2 TO N
210    S=0.5-1/(M+1)
220    FOR K=2 TO M-1
230    R=1
240    FOR J=2 TO K
250    R=R*(J+M-K)/J
260    NEXT J
270    S=S-R*B(K)
280    NEXT K
290    B(M) = S
300    NEXT M
310    FOR M=3 TO N-1 STEP 2
320    B(M) = 0
330    NEXT M
340    END SUB

The above code checks if the value of N you enter is the same one you entered the last time. If so, the code skips calling the subroutine BERN since it already has the values of the Bernoulli numbers from the last round of calculations.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(HP71B) Bernoulli Polynomials - Namir - 07-14-2023 10:00 PM
RE: (HP71B) Bernoulli Polynomials - C.Ret - 07-17-2023, 07:16 PM



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