Post Reply 
[VA] SRC#005- April, 1st Mean Minichallenge
04-07-2019, 06:03 PM (This post was last modified: 04-11-2019 02:02 PM by Maximilian Hohmann.)
Post: #10
RE: [VA] SRC#005- April, 1st Mean Minichallenge
Hello!

(04-07-2019 01:21 PM)rprosperi Wrote:  The 39gii is really a Prime- ; ...

The "poor man's Prime" so to say :-) I played all afternoon with it and it really is an interesting machine. Especially for the price you can find it for. It only crashed once during several hours (needed to take the batteries out to get it going again) which is not bad for this type of device.

Unfortunately HP does not care the least about us Macintosh users (different to Ti whose "Ti Connect" software has always been running on Macs as well). Although I was able to install the connectivity kit inside a Virtual Box it does not "see" the connected calculator... So I have to post photograhs of my results instead.

This is my 39Gii version of Valentin's program above. My attempts to pass a list, matrix or vector to a program resulted in the above mentioned crash, therefore I decided to use the inelegant way of storing the dataset in the global "L1" variable for lists. Entering the example data is done by typing {1,4,20.19} Sto Alpha L 1 Enter. (Note: Don't search for "Sto" on the keyboard, it is a menu funtion. What were these guys drinking when they designed this interface ?) As a genearal note, lots and lots of alternating "Alpha" and "Shift" pressing is necessary to program this calculator. A major, major, super major nuisance!

The "GMEAN" program itself - not optimised in any way - reads like this, maintaining Valentin's variable names:

EXPORT GMEAN(L)
BEGIN
LOCAL K,N,G,S,I;
L-2 -> K; (Note: the "->" is in reality a black arrow that can be entered by menu command "STO" only)
SIZE(L1) -> N; (Note: L1 is one of ten global variables for lists)
0->G;
IF K != 0 THEN (Note: Do not type "!=" here even if the manual says so. Use the crossed-out equal sign accessible only from some menu-submenu instead. This took me almost an hour to find out and fix...)
(extra Note: Back in the day when I paid for my mortgage by writing programs used to design large airliners I would not have checked against "0" here but against some very small number to make sure binary rounding stuff would not result in loss of human life. Now I couldn't care less.)
0->S;
FOR I FROM 1 TO N DO (Note: Do insert all blank spaces manually here, using Alpha and the "+" key. The smart menu that creates the control expressions unsfortunately does not instert blank spaces around them which even more unfortunately are required for the program to work. My Sinclair ZX81 from 1981 did a lot better in that respect.)
S+L1(I)^K -> S;
END;
(S/N)^(1/K) -> G; (Note: Some of the parentheses may actually not be necessary but I added them just in case. After some time I ran out of patiance for debugging and kept pressing the "(" and ")" instead - but the debugger itself is really not bad)
ELSE
1->S;
FOR I FROM 1 TO N DO
S*L1(i)->S; (Note: As in Valentin's program "S" is actually a product here, not a sum - this is for the special case of the geometric mean)
END;
S^(1/N)->G;
END;
RETURN G;
END;


This programme, by using the "EXPORT" before it's name, makes the function "GMEAN" globally available on the calculator. Just like "SIN" or "LN". To try it out one can either type it into the "Home" screen as a command, e.g. GMEAN(1) or use the interface of the "Prgm" function which will smartly prompt for all function values (in this case there is only one). I like that latter functionality, otherwise one would have to code it oneself. Valentin's examples could be easily verified that way.

To solve for the GMEAN = "Pi" challenge I used the graphing "App" of the calculator. It could of course have been done in many other ways as well. Also the necessary commands could have been added to the code, making it fully automatic.

However I stayed with the semi-automatic way of doing things (like operating one's autopilot in "HDG" and "ALT HOLD" mode instead of using "LNAV" and "VNAV") and in the "Symb" menu defined and checked (the latter bit is very important - forget the check marks which are only available through the menu! and nothing will happen) two functions (I have to insert a photo here because, as already written, my Macintosh and the Hp-39GII did not become intimate friends):

[Image: IMG_0129_640px.jpg]

Then I used the "Plot" key, manually set the boundaries for X from -1 to 5 and for Y from 1 to 20 and got the plot shown below. Within the Plot-screen simply use the "FCN->Intersect" menu and the value of K for which the generalized mean will be Pi is smartly shown at the bottom of the screen. Again, all this can somehow be programmed if one would want to present a fully autmatised version.

[Image: IMG_0128_640px.jpg]

Regards
Max

Note: Edited to reduce the picture size as requested
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC#005- April, 1st Mean Minichallenge - Maximilian Hohmann - 04-07-2019 06:03 PM



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