HP Forums

Full Version: Evaluate expression with HP50g
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I have a long algebraic expression in function of 'x' and I need to evaluate it for different values of 'x'. How can I do it in an intelligent way, without reentering the whole expression for each value of 'x'?
Hello vini.simoes,

The easiest way is to define a function and feed it with the values you like.

Maybe you aren't not familiar with this calc. The best way is to choose in the "MODE" app:

a) RPN
b) Set exact mode in submenue "CAS"
c) Set flag 117 in submenue "FLAGS", that's important because you can access your own objects with the keys "F1" to "F6" show in the last line of display (inverted, background black foreground "white").

For example:

Your complicate expression is x^2;
Key in the following

'MYFUN(X) = X^2' Don't forget the single quotes they are important!

Then press the key "Right Shift" and then press the "SYMB", now you get the catalogue of all functions and look for the command "DEFINE" and press "OK".

Now you get a new objekt that works like a build in function.

Key in:


and then press where in the last line of display is MYFUN located (let's say at the fourth position), you press "F4" and you get the result you intended:

Peacecalc is correct but here are a few things to simplify his method.

Instead of searching the catalog by pressing [Right Shift] [SYMB] for the function "Define", you can simply press the [left shift] button and then press the [ 2 ] button. It should say "DEF" above the [ 2 ] button in white text, which means define.

The second thing that Peacecalc was unclear about is you have to press the [VAR] button in order to see the "MYFUN" variable name.

The third thing I have to say is that you do not need to have flag 117 set. When pressing the [VAR] button, it is always a soft menu. Also, when using the Catalog, it is always a CHOOSE box. So flag 117 is irreverent in this problem.
Use the numerical solver

Red right Shift followed by NUM.SLV (on 7 key)

Select "1.Solve equation"

Highlight "Eq: " and select EDIT (F1 key)

Enter your equation in the form y=f(x)

Below the equation you will be presented with

Highlight x and enter a value
Highlight y and select SOLVE (F6 key)

Repeat last two steps for as many x values as needed.

(The numerical can also be used with many variables e.g. P*v=n*R*T etc.)
(06-23-2017 10:55 AM)BartDB Wrote: [ -> ]Use the numerical solver

(The numerical can also be used with many variables e.g. P*v=n*R*T etc.)

I'm a big fan of the numeric solver as well. As an added benefit, you can solve the function backwards. For instance if you have a desired Y value, you can enter it and solve for X (note you may have to play with an initial guess for X to find the right answer if there are multiple possibilities).
I find The SOLVE soft menu (page 6-26 of the user guide) very practical.
To save keystrokes, I often "cheat" and use the "lim" command like this:

1) Put any expression in 'X' on the stack. MUST be 'X' (or whatever your current independent variable is; press MODE CAS, see top line).
2) Put the desired value for X on the stack.
3) Execute lim (shortcut: left-shift 4, LIMIT, lim)

All the X's will be replaced by the number, and the expression evaluated.

If you want to substitute several values, put them in a list, and all will be handled at once. Example:

{6 7 8}
--> { 79 114 155 }
... that's what the polynomial evaluates to when 6, 7, and 8 are substituted into 'X'.

It's not what lim was intended to be used for, but I find it's more keystroke efficient than other ways of substituting values into X.
Nice ideas!

If your expression is on the stack for example '2*x' and you need exact results or CAS capabilities, you can do :

->         @ right arrow to swap 
=          @ RShift W
DEF        @ Lshift 2

If you have to enter the full expression, you can use the equation writer, F(x)=2*x then ENTER and DEF
Reference URL's