# HP Prime – The missing command

The HP Prime Missing Command

Frequently I must inspect the values that a function takes in a list of points or I have to take some samples of the function in a neighborhood of a point X0.

With HP Prime I can enter the function in “Function App” and plot it. I can also inspect the numerical value it assumes by means of NUM, but it isn’t an easy way to do my job…

So I wrote down some lines of code to make my life easier. I write down – my – missing HP Prime command.

My missing command takes three forms: FORCALC, LISTCALC and FORCALCFORM

FORCALC and LISTCALC use the function stored in F0 function variable. in FORCALCFORM you can enter the function you want to sample directly in an input form.

FORCALC takes three parameters in input:

• X_FR – X FROM Value; the start value of the interval to sample;
• X_TO – X TO Value; the end value of the interval to sample;
• X_STEP – the increment to add at each loop.

Usage: FORCALC(1,5,0.2)

Output: FORCALC samples the function stored in F0 variable from X=1,to X=5, 20 times (0.2 increment at each loop)

Source code:

```EXPORT FORCALC(X_FR,X_TO,X_STEP)
BEGIN
LOCAL OUT={};
FOR X FROM X_FR TO X_TO STEP X_STEP DO
MSGBOX("X="+X+" F0="+F0(X));
CONCAT(OUT,F0(X))▶OUT;
END;
RETURN(OUT);
END;
```

LISTCALC takes one parameter in input:

• LL – List of value to test. The list contains the points you want to sample.

Usage: LISTCALC({1.0, 1.5, 10.0})

Output: LISTCALC samples the function stored in F0 variable in tree points 1.0, 1.5, 10.0.

Source code:

```EXPORT LISTCALC(LL)
BEGIN
LOCAL OUT={};
FOR I FROM 1 TO SIZE(LL) DO
MSGBOX("X="+LL(I)+" F0="+F0(LL(I)));
CONCAT(OUT,F0(LL(I)))▶OUT;
END;
RETURN(OUT);
END;```

FORCALCFORM combines the two tools in one.

It takes no parameters in input, but it shows an input form: In FN you have to input the function to sample, in X_FR the start value of the interval to sample, in X_TO the end value of the interval to sample, in X_STEP the increment to add at each loop. In POINT_LIST you can enter the list of points to sample. If you insert something different from {} in POINT_LIST, X_FR, X_TO, X_STEP will be ignored.

Source code:

```EXPORT FORCALCFORM()
BEGIN
// Pay attention, it overwrites the variable F0
LOCAL OUT={};
LOCAL FN="";
LOCAL X_FR=0;
LOCAL X_TO=0;
LOCAL X_STEP=0;
LOCAL POINT_LIST={};
INPUT({FN,X_FR,X_TO,X_STEP,POINT_LIST});
FN▶F0;
IF SIZE(POINT_LIST)==0 THEN
FOR X FROM X_FR TO X_TO STEP X_STEP DO
MSGBOX("X="+X+" F0="+F0(X));
CONCAT(OUT,F0(X))▶OUT;
END;
ELSE
FOR I FROM 1 TO SIZE(POINT_LIST) DO
MSGBOX("X="+POINT_LIST(I)+" F0="+F0(POINT_LIST(I)));
CONCAT(OUT,F0(POINT_LIST(I)))▶OUT;
END;
END;
RETURN(OUT);
END;```

Simple and useful.

Enjoy.

You may find interesting also this post: http://informaticasanitaria.it/2014/12/06/hacking-hp-prime/

Pierfrancesco Ghedini Quest’opera è distribuita con Licenza Creative Commons Attribuzione 3.0 Italia.