HP Forums
Solving for equations the HP50, 49.. way. - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Solving for equations the HP50, 49.. way. (/thread-19690.html)



Solving for equations the HP50, 49.. way. - Luigi Sardella - 03-20-2023 11:07 PM

With the RPN based HP calculators (UP48,..50) one could define an expression, or equation with several variables; give it a name; and then solve for one of the variables, assigning values to the others. It worked also inside a program, with the ROOT command.
Can I do the same with my new Prime, and how? The documentation I have read is scanty and unclear; all trials I made EXPORTing code snippets and variables have been met with Syntax Error flags.
Thank you for help.


RE: Solving for equations the HP50, 49.. way. - roadrunner - 03-23-2023 04:55 PM

Did you try the solver app?

-road


RE: Solving for equations the HP50, 49.. way. - Luigi Sardella - 03-23-2023 08:57 PM

Sure did I try the solver app; but I did not find it as useful as I would like. I have little use of ten equations, or expressions, named E1..E10. To be clear, let's suppose I want an equation for LC resonant circuits. With the RPN calculator I make so:

'freq = (1/pi) / sqrt(induct*capac)'
ENTER
'LC_eqn'
ENTER
SWAP
STO

and then I can use this equation inside a program, and solve it for one of its variables using ROOT; or I solve it with the solve_equation app.
Thanks for Your attention.


RE: Solving for equations the HP50, 49.. way. - BruceH - 03-24-2023 05:18 PM

(03-23-2023 08:57 PM)Luigi Sardella Wrote:  Sure did I try the solver app; but I did not find it as useful as I would like. I have little use of ten equations, or expressions, named E1..E10. To be clear, let's suppose I want an equation for LC resonant circuits. With the RPN calculator I make so:

'freq = (1/pi) / sqrt(induct*capac)'
ENTER
'LC_eqn'
ENTER
SWAP
STO

and then I can use this equation inside a program, and solve it for one of its variables using ROOT; or I solve it with the solve_equation app.
Thanks for Your attention.

I entered the expression F=(1/pi)/sqrt(D*C) into the Solve app's symbolic view as E1, then pressed NUM and was presented with entry fields for F, D & C. I entered some random numbers and it solved away merrily.

Perhaps you hadn't created the variables you wanted to use (induct etc) in advance?

If you enter "0 Sto▸ induct" it will ask if you want to create the variable 'induct'. You can then use this in the E1 expression instead of D.

If you have more than 10 expressions then you can save a copy of the Solver app and so gain another 10 expressions. Repeat if more are required.


RE: Solving for equations the HP50, 49.. way. - Luigi Sardella - 03-24-2023 05:52 PM

One correction in my formula: 1/(2*pi) instead of 1/pi.

I tried the solve app after defining the variables with meaningful names, and it worked. Now I would like to give each problem its name. Can I save those apps with names?

Also, in the RPN machines the equation to be solved can be computed in a program, not by a single formula. In the example I made, it would be

<< freq 1 2 / pi / induct capac * sqrt / - >>

'LC_eqn'

STO

Is it possible to use the HP Prime programming language in a similar way? And what about calling a named solve app from within a HPPPL program?

Many thanks for your help.


RE: Solving for equations the HP50, 49.. way. - Luigi Sardella - 03-24-2023 05:54 PM

Sorry, I forgot two ENTERs and one SWAP in the above...


RE: Solving for equations the HP50, 49.. way. - gehakte_bits - 03-24-2023 06:06 PM

When using the Solver, you have to use globals (A-Z etc.) or create globals (pre-define or EXPORT var1, var2; )
1) You can define (<Shift> <Define>) a function_name with a function "2X=2Y" followed by E1:=EVAL(function_name),
then use the Solver, check <E1>, and solve in <Num>

2) or use a program (same Solver concept) such as
Code:
// 2023.0322 pretty-prime v0.3b
#pragma mode(separator(.,;) integer(h32))

// for solver declare global vars, or use 'home' vars
EXPORT Bsea_p1,Bair_p2,B_t,B_h;             // pressure 1, 2, temp, height

EXPORT Baro()
BEGIN 
LOCAL x;
  // initial seed values
  Bsea_p1:=1007;                            // p1
  Bair_p2:=974;                             // p2
  B_t:=20;                                  // temp
  B_h:=286;                                 // height

  // seed solver equate
  E2:='Bair_p2=Bsea_p1*(1-(0.0065*B_h)/(B_t+0.0065*B_h+273.15))^5.257';
  FOR x:=0 TO 9 DO 
    Solve.UNCHECK(x);
  END;
  Solve.CHECK(2);                           // select E2
  STARTAPP("Solve");
  STARTVIEW(2);                             // show num view
END;



RE: Solving for equations the HP50, 49.. way. - Luigi Sardella - 03-24-2023 09:35 PM

(03-24-2023 06:06 PM)gehakte_bits Wrote:  When using the Solver, you have to use globals (A-Z etc.) or create globals (pre-define or EXPORT var1, var2; )
1) You can define (<Shift> <Define>) a function_name with a function "2X=2Y" followed by E1:=EVAL(function_name),
then use the Solver, check <E1>, and solve in <Num>

2) or use a program (same Solver concept) such as
Code:
// 2023.0322 pretty-prime v0.3b
#pragma mode(separator(.,;) integer(h32))

// for solver declare global vars, or use 'home' vars
EXPORT Bsea_p1,Bair_p2,B_t,B_h;             // pressure 1, 2, temp, height

EXPORT Baro()
BEGIN 
LOCAL x;
  // initial seed values
  Bsea_p1:=1007;                            // p1
  Bair_p2:=974;                             // p2
  B_t:=20;                                  // temp
  B_h:=286;                                 // height

  // seed solver equate
  E2:='Bair_p2=Bsea_p1*(1-(0.0065*B_h)/(B_t+0.0065*B_h+273.15))^5.257';
  FOR x:=0 TO 9 DO 
    Solve.UNCHECK(x);
  END;
  Solve.CHECK(2);                           // select E2
  STARTAPP("Solve");
  STARTVIEW(2);                             // show num view
END;



RE: Solving for equations the HP50, 49.. way. - Luigi Sardella - 03-24-2023 09:37 PM

Many thanks for your kind and instructive replies.


RE: Solving for equations the HP50, 49.. way. - BruceH - 03-25-2023 12:19 AM

(03-24-2023 05:52 PM)Luigi Sardella Wrote:  One correction in my formula: 1/(2*pi) instead of 1/pi.

I tried the solve app after defining the variables with meaningful names, and it worked. Now I would like to give each problem its name. Can I save those apps with names?

Saving an app under another name is covered in the manual on page 64. Press Apps, select the Solver app, press Save and you'll be prompted to give a new name. The new copy will appear at the end of the list of Apps - so you may need to scroll the screen (using down arrow or dragging the screen) to see it. You can copy your copy as well to save starting from scratch if required.

Quote:Also, in the RPN machines the equation to be solved can be computed in a program, not by a single formula. In the example I made, it would be

<< freq 1 2 / pi / induct capac * sqrt / - >>

'LC_eqn'

STO

Is it possible to use the HP Prime programming language in a similar way? And what about calling a named solve app from within a HPPPL program?

Many thanks for your help.

You can create a user-defined function and then reference that in the solver app. Some restrictions apply - it must be numerically solvable which basically means not constant, and not discontinuous.

Page 508 in the manual tells you how to do this. It would be well worth your time doing the examples and reading-up on the other capabilities. For example, SHIFT+Info (Info is on the APPS key) opens a notes page where you can put some reminder notes that are specific to that copy of the app - handy for reminding yourself what the equation variables represent, for example.