Tampilkan postingan dengan label hp 9g. Tampilkan semua postingan
Tampilkan postingan dengan label hp 9g. Tampilkan semua postingan

hp 9g: Sample Programs

hp 9g:  Sample Programs


Introduction


As I mentioned in yesterday's blog, today's blog will have some sample programs for the hp 9g.   


The hp 9g's programming language is a mix of C and Basic, and is unique from the rest of the Hewlett Packard calculators.    The hp 9g has 400 steps of programming memory to be allocated among 10 program files, P0 through P9.   


The 9g has 26 variables, but can be extended up to 53 variables at the cost of program steps.  The square brackets indicate indirect addressing.  The number in the square brackets is the number of steps away from the variable.   Any variable beyond Z (Z[0], A[25]) must be addressed in this fashion.  


Example: 

A[0] calls up A

A[1] calls up B

...

A[25] calls up Z. 


We can use any letter, but I recommend using either A or Z. 



hp 9g Program:  Integer Division


This program gives the quotient and remainder of N ÷ D.  The program here assumes you enter positive integers, and some code can be entered for checking inputs.  


INPUT N

INPUT D

Q=INT(N/D)

R=N-Q*D

PRINT Q," R",R

END


Examples:


N = 4379, D = 8;  Result:  547 R3


N = 5884, D = 29;  Result:  202 R26



Note:  The PRINT command converts variable values to strings automatically, without the need for a string or STR$ command.


hp 9g Program:  Arithmetic-Geometric Mean


This program determines the AGM given two numbers A and G.


INPUT A

INPUT B

PRINT "ACC. 10^-8"

Lbl 0:

X=.5(A+G)

Y=√(AG)

If (ABS(X-Y)<10^(-8))

Then {Goto 1}

A=X

G=Y

Goto 0

Lbl 1:

Print "ANS= ", X


Examples:


A = 1.3, G = 1.5,   Result:  ANS ≈ 1.39821143


A = 20, G = 45,  Result:  ANS ≈ 31.23749374



Notes:  


10^ is from [ 2nd ] (10^x) the antilog function.


The label command must have the colon character after the label number, or a syntax error occurs.  


If you run a program from the Main mode by the [ PROG ] key, you will be transferred to Program mode when the program finishes.


hp 9G Program: The Maximum Value of A through X



Y = maximum value

Z = counter variable


PRINT "MAX(A:X)"; ◢

FOR(Z=2;Z<23;Z++){

IF(A[Z]>Y)

THEN{Y=A[Z]}};

PRINT "MAX=",Y;

END


Example:  


Clear all variable in the MAIN mode by CL-VAR

Set up variables: 


A = 12, D = 24, E = 37, G = 40, S = 19, T = 16, U = 7

Result:  MAX= 40


Notes:   


++ is from the Instruction menu, it is a smaller-jointed double plus.


When the program encounters a run/stop instruction (◢), the last message is displayed.  Continue execution by pressing the equals key [ = ].  


hp 9g Program:  Plotting y = A * sin(B * x + C) + D


The programming mode does not offer a lot of support when it comes to graphs.  


PRINT "SINE"

SLEEP(.5)

INPUT A,B,C,D

RANGE(-2π,2π,π/4,-A,A,1)

Graph Y=A*sin(BX+C)+D

PRINT "PRESS G<>T"

END




A = 1, B = 1, C = 0, D = 0



Notes:


Prior to running the program, set the angle mode to Radians through the [DRG] key.  Also, press [ 2nd ] [ → ] (CLS) to clear the graph screen.  Unfortunately, neither of these commands can be programmed.  


Plots from programs cannot be traced.


When the program ends, you will need to switch to Main mode, press [G<>T] to show the graph.   Not a very efficient way of showing a graph.  



That is a sample of the programs for the hp 9g.  Good for number crunching, kind of a little bit to be desired for graphics.


Until next time,


Eddie 



All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Retro Review: hp 9g

Retro Review:   hp 9g







Quick Facts:


Model:  hp 9g

Company:  Hewlett Packard

Years:  2003 (short production life)

Battery:  2 x AR76 or 2 x LR 44

Display:  10 digits, 2 digit exponent

Logic:  Algebraic - type in expressions the way you write them

Memory:  400 bytes, but can be designated as additional memory registers

Memory Registers:  26, can be extended to 59 memory registers 

Slide Case

Range:  9.999999999 * 10^-99 to 9.999999999 * 10^99, real numbers only


The hp 9g is a small sized graphing calculator, similar to the Citizen SRP-325G and the Casio fx-6300g.  The 9g offers more features than the fx-6300g. 


Features


*  Trig, logs, power, permutations, combinations, hyperbolic functions

*  Random numbers and integers, integer factorials, fraction, integer, sign, absolute value

*  Maximum, minimum, sum, and average up to 10 numbers 

*  Base conversions (decimal, binary, octal, hexadecimal) with Boolean logic (NOT, AND, OR, XOR, NXOR, NEG)

*  20 scientific constants, all SI units   

*  Conversions:  length, area, temperature, volume, mass, calories, pressure (always a good thing to have!)

*  Function graphing, more than one function can be plotted on top of each other.

*  One and Two Variable Statistics

*  Regressions:  linear, logarithmic, exponential, power, inverse, quadratic


Percent


The percent (%) just divides the argument by 100.   For example:  58% converts the number to 0.58.   That is good for multiplying or dividing but not for direct addition and subtraction.


Undo


The [ 2nd ] [ ENTER ] brings back the last thing that has been cleared or deleted.  I don't think this brings back programs that have been deleted though.  


Normal Distribution - One Variable Statistics


Normal distribution is based on one-variable statistics.  The t value is based on data point a_x, which is entered in the DATA menu.  The t point is calculated with the formula:


t = (a_x - mean) / σ


Three areas can be calculated:


P(t):  lower tail cumulative distribution

Q(t):  absolute value of the cumulative distribution between 0 and t

R(t):  upper tail cumulative distribution (I think)


Process Capability - One or Two Variable Statistics


A very unique function, available to the 9G are process capability calculations.  Depending on the mode, the following can be calculated:


C_ax = capability accuracy of x values

C_ay = capability accuracy of y values

C_px = potential precision of x values 

C_py = potential precision of y values

C_pkx = minimum of capability of values or capability precision of x values

C_pky = minimum of capability of values or capability precision of y values

ppm = parts per million (One variable stat mode only)


See the User Manual for formulas.


Storing a Formula


Formulas can be stored into any one of the program areas (P0- P9), using the [ SAVE ] [ PROG ] key sequence.  We can run programs from the Main mode by pressing [ PROG ] with 0 - 9.  Variables are prompted.


Example:  


X^2-3X+1 [ SAVE ] [ PROG ] 9  stores x^2 + 3*x + 1 into program P9.


Evaluating the function at x = -1 and x = 8.5


[ PROG ] 9 [ = ], (formula is displayed), [ = ], [CL/ESC], -1 at the X prompt, [ = ], result:  5


[ PROG ] 9 [ = ], (formula is displayed), [ = ], [CL/ESC], 8.5 at the X prompt, [ = ], result:  47.75


At all prompts, to enter a new number, press [CL/ESC] first, very important.  


Screen


The screen is split up in different sections.  


There are two lines during calculations.  The top line shows what is being calculated, while the bottom line shows the results on the right hand of the screen, in a smaller font.  


In program editing mode, we only get the top line as the bottom of the screen is taken by the two lines EDIT:  and *MAIN* (*DEC/HEX/OCT/BIN* for BASE-N programs).   


In data input, only the top line shows the data points.   


If you graph a function, the left side of the screen is the graph.  Pressing [ Trace ] will alternate between showing the x-coordinate and the y-coordinate.   Personally, I would like it better if both x and y were shown.   The small graph screen means that we really can't do much (no shading, no integration, have to arrow to approximate roots, but can draw lines and plot points).   


Not perfect, but one of the best uses of a small graphics calculator screen.  


Programming


The hp 9g has 400 steps that can be divided among 10 programs (P0 to P9).   Each program can either work in Main mode or Base mode.  Base mode programs are designated for base conversions and Boolean logic.  


The programming language is somewhat like the C programming language.   Each instruction or line can, but doesn't have to end with a semicolon (;).    However, any command called from the INST menu inserts a semicolon.  


Some program commands include:


INPUT var1[, var2, var3... ]  

Input with prompt "[var] = ".  


PRINT "text"/var, "text"/var, ...     

Display strings and variable values


IF (condition) THEN { do if true, commands separated by a semicolon } ; ELSE { do if false, commands separated by a semicolon }

If-Then-Else structure.  The Else part is optional.


Lbl/GOTO n

Lables can take values 0-9


GOSUB PROG n;

Calls a subroutine program n.  Semicolon is required.


SLEEP(time)

Pauses execution for seconds up to 105 seconds.


SWAP(varA, varB)

Swaps the values of variables A and B


; ◢

Stops the program and shows immediate results.   Press [ = ] to continue.


var++, var--   (The ++ and -- is from the INST menu, not pressing + or - twice)

Increase or decrease the variable by 1 after the expression is evaluated.


++var, --var (The ++ and -- is from the INST menu, not pressing + or - twice)

Increase or decrease the varaible by 1 before the epression is evaluated.


FOR(start condition; continue condition; next expression) {loop commands separated by a semicolon}

For loop that works more like a WHILE loop


start condition

WHILE continue condition

loop commands

next expression

END


The FOR loop is in C language.  This is the same syntax of the FOR equation editor command of the Plus42.  


On tomorrow's blog I will have sample programs for the hp 9g.  


Final Thoughts... For Now


I wish the hp 9g had better manuals or manuals that were formatted like a book instead of two large sheets.   But better than nothing and the documentation is detailed.  


The biggest drawbacks are the lack of screen space and small amount of programming steps.  Despite this, the hp 9g is an underrated marvel and is very unique in a line of HP calculators.    


Sources


hp 9g User Manual:  https://literature.hpcalc.org/official/hp9g-ug-en.pdf


hp 9g Examples:  https://literature.hpcalc.org/official/hp9g-htg-en.pdf


"HP 9g"  Wikipedia.   Last edited May 15, 2022.   Last Accessed September 24, 2022.  https://en.wikipedia.org/wiki/HP_9g

 


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Backlink 9999 Traffic Super

Order Now...!!!!