Post Reply 
Comments and discussion on Valentin's 4th "Then and Now" - Area
01-19-2023, 09:23 PM (This post was last modified: 01-19-2023 09:26 PM by J-F Garnier.)
Post: #5
RE: Comments and discussion on Valentin's 4th "Then and Now" - Area
First of all, thanks to Valentin for this new problem. It kept me busy for long hours.
Also the kind request to postpone our results for a few days was an interesting exercise.

For now, I will just make a couple of comments purely focusing on the programming aspects:

(01-19-2023 05:08 PM)Valentin Albillo Wrote:  1  DESTROY ALL @ DIM U @ H=1/3 @ D=FNROOT(1,1,SQR(FNG(FVAR))-FVAR)
2  DISP "Area:";FNI(0,D)+FNI(D,FNY(2.83))+FNI(FNY(-4.08),FNY(-4.05))

3  DEF FNG(Y)=-LN(Y*Y/30.07+EXP(-SIN(Y))) @ DEF FNY(Y)=FNROOT(Y,Y,FNG(FVAR))
4  DEF FNI(A,B)=INTEGRAL(A,B,1/10^10,FNW(IVAR)) @ DEF FNR(X)=SGN(X)*ABS(X)^H
5  DEF FNW(Y) @ U=SQR(FNG(Y)) @ FNW=FNR(Y+U)-FNR(Y-U)

1. You may wonder why Valentin explicitly declared the variable U ("DIM U"), and not the others.
Don't remove this DIM statement! Its purpose is related to a HP-71B bug, still present in the latest 2CDCC version and documented here, that I can summarize as:
don't create new variables in the functions called by INTEGRAL or FNROOT, but create/declare them before.

Matter of fact, my own solution is buggy in that respect, since the X, X1 and X2 variables are created in the FNF function called by INTEGRAL:
(01-12-2023 09:34 AM)J-F Garnier Wrote:  280 DEF FNF(Y)
290 X=SQR(-LOG(FNR(Y)))
300 X1=ABS(Y-X)^(1/3) @ IF Y<X THEN X1=-X1
310 X2=ABS(Y+X)^(1/3) @ IF Y<-X THEN X2=-X2
320 FNF=X2-X1
330 END DEF
During my program development I manually called FNF surely several times before running the INTEGRAL function on it, so it was harmless, still to be safe X, X1 and X2 should be created before, for instance with:
55 REAL X,X1,X2

2. The "1/10^10" expression may look inefficient and be better replaced by 1E-10.
The problem is that the HP-71 decompiles this value in standard format as .0000000001 that is difficult to re-read. This is one of the few minor annoyances of the HP-71 BASIC.
I used the same 10^n trick for readability in my own solution.

J-F
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Comments and discussion on Valentin's 4th "Then and Now" - Area - J-F Garnier - 01-19-2023 09:23 PM



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