MultiFactorial using 19BII Solver



Post: #6

Yesterday, Egan posted how to calculate multiFactorials, which I had never even heard of before his post. See following link

MF Link

Egan had posted a HP-15C program that would calculate it.

I've been playing around with the solver on the HP-19BII and thought I'd give a try at translating his 15C program to a solver equation.

I came up with the following:

MF = SIGMA(K:1:
IF(X=N OR N=1:1:(X/N)+1):1:
IF(K=1:0*L(M:X):0*L(X:X-N)+0*L(M:G(M)*X)))
+ IF(N=1:FACT(X):G(M))

Just enter X and N and press MF to solve.

I'm still trying to learn how to use the solver, and this is my first try with the SIGMA function. So would appreciate any suggestions, comments, etc on how to do it better.

Thanks,

Bill


Edited: 2 Mar 2007, 8:40 a.m.


Post: #7

After a little more thinking and reading, I have come up with the following solver equation:

MF = IF (N=1:FACT(X):
IF (X<=N:X:
SIGMA(K:1:(X/N)+1):1:
IF(K=1:0*L(M:X):0*L(X:X-N)+0*L(M:G(M)*X)))
+ G(M)))

It now checks for the simple cases of N=1 or where X <= N outside the SIGMA function.

Is there anyway to get rid of the Temporary Variable M?

Thanks,

Bill

Edited: 2 Mar 2007, 1:50 p.m. after one or more responses were posted


Post: #8

Ooops...

Just noticed that if N is a multiple of X, then the solver always returns zero for MF, since the the final pass through the SIGMA loop would have X=0.

I could change the final index from (X/N)+1 to (X/N)+0.99 which would be correct for most cases, but would still fail under certain conditions. If the 19BII had the MOD fuction, then I could do

IF (MOD(X/N)=0:X/N:(X/N)+1

which would then add one more pass ONLY if N wasn't a multiple of X.

I could also add an IF statement to check for when X=0 inside the SIGMA function and ignore multiplication. Not very elegant.

Anybody have any other suggestions?

Thanks,

Bill


Post: #9

Bill:

The 19BII does have a modulo function, MOD(X:Y)

Bob


Post: #10

Hi Bob,

Quote:
The 19BII does have a modulo function, MOD(X:Y)

Boy do I feel stupid - that's what I get for not checking the manual first. Thanks.

I just made the correction and it now works great. Corrected version follows:

MF = IF (N=1:FACT(X):
IF (X<=N:X:
SIGMA(K:1:IF (MOD(X:N):X/N:(X/N)+1):1:
IF(K=1:0*L(M:X):0*L(X:X-N)+0*L(M:G(M)*X)))
+ G(M)))

Thanks,

Bill


Edited: 2 Mar 2007, 2:47 p.m.


Forum Jump: