[HP Prime] Function selection
|
09-21-2014, 01:30 PM
(This post was last modified: 02-01-2015 03:16 PM by Han.)
Post: #1
|
|||
|
|||
[HP Prime] Function selection
This is an example of how to programmatically use functions for evaluation without altering the user's original functions. The technique can be used for apps and programs. Three commands are available to check if a function has been selected (ISCHECK), to select a function (CHECK), and to deselect a function (UNCHECK).
Goals:
We use a variable fx and initialize it to an empty string. This string keeps track of the "current" function. Likewise we use another variable recompute to determine if recalculations are actually necessary. A user may possible have re-created the same function and placed it into a different slot in the [Symb] screen. In such a scenario, recalculations is highly likely to be unnecessary. The first step is to loop through F0-F9 to check if any functions have been selected. We keep track of the total number of selected functions in ftot. In this example, we only want one function selected. We use fsel to keep track of the selected function; if only one function has been selected, then fsel will simply be the index (from our loop) for which ISCHECK(i) tested as true. While it may seem that fsel could be compared to its prior value to see if the selected function has changed, we cannot account for cases when the function has been copied (i.e. the function has not changed although it may have moved from F0 to, say, F3) using this technique. So instead, we compare the currently selected function with fx. To create a string from F0, F1, …, F9, we can use the STRING() command: STRING(F0) will return a string equivalent of the formula stored in F0. Since our selection is dynamic, we have to embed this within the EXPR() command and then store the string into fnew. Lastly, comparing the string fx against fnew will allow us to know if the function has truly changed since the last time we run this program. If so, recompute is set to 1 and we can use this within our calculations routine. Below is the code that will do all these steps: Code: fx:=""; Now that our selected function is stored into fx, we can then use the builtin function names F0, F1, …, F9 to do our evaluations. It may be the case that the user already has formulas in all these built-in function names. We can copy, say, F0 into a temporary string, use F0 to do our calculations, and then restore F0. Code:
These two programs, along with our own computefunc() program, need to be within the same source file. Make sure that computefunc() exits gracefully so that F0 is restored to its original state! If necessary, surround computefunc() with an instance of an IFERR block. Happy programming! Han Graph 3D | QPI | SolveSys |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)