Post Reply 
HP Prime programmable eq solver
01-04-2014, 11:04 PM
Post: #1
HP Prime programmable eq solver
Hello,
a first attempt in trying to create an equation library for the Prime.
It has a lot of limitations.

If you want to test it please create two lists:
EQLIB:={"S=A*B", "S=A*B/2"}
EQLIBNAME:={"Surface of a rectangle", "Surface of a triangle"}
I created these list names just to prevent overwriting the L0-L9 by mistake.

Anyway it was a good example for me to launch/use APPS like the SOLVE from the HPPL.

Code:

EXPORT PSOLVE()
BEGIN
LOCAL A,B,C:="",D:="";
// REPEAT 
 CHOOSE(B,"SOLVE EQ LIBRARY","SOLVE AN EQUATION","ADD AN EQUATION","EXIT");
  CASE
  IF B=1 THEN
   CHOOSE(A,"SOLVE EQ LIB", EQLIBNAME);
   E1:= EQLIB(A);
   STARTAPP("Solve");
   CHECK(1);
   UNCHECK(2);
   UNCHECK(3);
   UNCHECK(4);
   UNCHECK(5);
   UNCHECK(6);
   UNCHECK(7);
   UNCHECK(8);
   UNCHECK(9);
   UNCHECK(0);
   STARTVIEW(2,0);
  END;
  IF B=2 THEN
  INPUT({C,D},"INSERT AN EQ",{"EQ: ","EQ NAME:"},{"INSERT AN EQ. AS A STRING","INSERT AN EQ. NAME AS A STRING"});
  EQLIBNAME(0):=D;
  EQLIB(0):=C;
  END;
  END;
//UNTIL B=3;

END;

As you can see i commented the REPEAT..UNTIL loop because there is no HALT..CONTINUE command like in the 48. When the solve APP is launched, the program doesn't stop showing a new session of CHOOSE before giving you the time to solve for a variable. Maybe here a GETKEY could do the trick.

The other limitation is that i used only A...Z variables in order to avoid to declare the variable prior to RUN the program. There should be a way to retrieve a list of variables from a equation but i still didn't find it.

Please suggest how i could improve it. I am sure it can be improved.

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
01-05-2014, 01:15 PM
Post: #2
RE: HP Prime programmable eq solver
Hi

I had the same idea, but I just had an ide before i saw your code, so I use it in an app instead.
Create 3 variables,
EQLIB:={{"S=A*B", "S=A*B/2"},{"R=U/I","P=U*I"}}
EQLIBNAME:={{"Surface of a rectangle", "Surface of a triangle"},{"Ohms law","Effect"}}
EQTYPE:={"Area","Electric"}

Copy the solve app and name it EQLib

Edit the program EQLib (App)
Quote:TYP,EQ;
EXPORT EQLib()
BEGIN
END;

VIEW "Start",START()
BEGIN
STARTVIEW(7,0);
END;

VIEW "Select type",STYPE()
BEGIN
CHOOSE(TYP,"Select type",EQTYPE);
STARTVIEW(7,0);
END;

VIEW "Solve EQ Lib",SOLVE()
BEGIN
LOCAL I;
CHOOSE(EQ,"Solve EQ Lib",EQLIBNAME(TYP));
E1:=EQLIB(TYP,EQ);
FOR I = 0 TO 9
UNCHECK(I);
END;
CHECK(1);
STARTVIEW(1,1);
STARTVIEW(2,1);
END;

VIEW "Add Equation",ADD()
BEGIN
LOCAL Equation:="", EQname:="";
INPUT({Equation,EQname},EQTYPE(TYP) + " Insert an EQ",{"EQ: ","EQ Name: "},{"Insert an EQ as string","Insert EQ name as string"});
EQLIBNAME(TYP,0):=EQname;
EQLIB(TYP,0):=Equation;
END;
Find all posts by this user
Quote this message in a reply
01-05-2014, 03:14 PM
Post: #3
RE: HP Prime programmable eq solver
Hello Lars,
interesting approach. i am curious to see how it looks like but unfortunately no way to go through..

I had an error in the:
...FOR I=0 TO 9... loop that i replaced by a ...FOR I FROM 0 TO 9... but now i have an error in the ...VIEW "Solve eq lib", SOLVE()... function.

Could you please check it? i am interested on that solution,

thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
01-05-2014, 03:27 PM
Post: #4
RE: HP Prime programmable eq solver
In the for loop it should be I:= , and the first STARTVIEW should be STARTVIEW(0,1)
Have you create all variables? EQTYPE

And in the ADD function it should be

IF INPUT({Equation,EQname},EQTYPE(TYP) + " Insert an EQ",{"EQ: ","EQ Name: "},{"Insert an EQ as string","Insert EQ name as string"}) THEN
EQLIBNAME(TYP,0):=EQname;
EQLIB(TYP,0):=Equation;
END;

so we don't end up with empty names and equations
Find all posts by this user
Quote this message in a reply
01-05-2014, 03:37 PM
Post: #5
RE: HP Prime programmable eq solver
I succeed to to download the code from calculator ( on a Mac!!!), so there should be no errors

And I use code tag instead of quote :-)

Code:

TYP:=1,EQ;
EXPORT EQLib()
BEGIN
END;

VIEW "Start",START()
BEGIN
  STARTVIEW(7,0);
END;

VIEW "Select type",STYPE()
BEGIN
  CHOOSE(TYP,"Select type",EQTYPE);
  STARTVIEW(7,0);
END;

VIEW "Solve EQ Lib",SOLVE()
BEGIN
  LOCAL I;
  CHOOSE(EQ,"Solve EQ Lib",EQLIBNAME(TYP));
  E1:=EQLIB(TYP,EQ);
  FOR I := 0 TO 9 DO
    UNCHECK(I);
  END;
  CHECK(1);
  STARTVIEW(0,1);
  STARTVIEW(2,1);
END;

VIEW "Add Equation",ADD()
BEGIN
  LOCAL Equation:="", EQname:="";
  IF INPUT({Equation,EQname},EQTYPE(TYP)+" Insert an EQ",{"EQ: ","EQ Name: "},{"Insert an EQ as string","Insert EQ name as string"}) THEN
    EQLIBNAME(TYP,0):=EQname;
    EQLIB(TYP,0):=Equation;
  END;
END;
Find all posts by this user
Quote this message in a reply
01-06-2014, 09:47 AM
Post: #6
RE: HP Prime programmable eq solver
I think I got some problem after creating this variables, if I try to enter LIST editor or MEM, then the calculator reboots!! I'm not sure if the EQLIB, EQLIBNAME and EQTYPE is cause of these problem but there are suspicious. Is there a way to delete these variables? I tried to do a EQLIB:={}, but the variable remains as a variable and the MEM and LIST editor still reboots calculator....
Find all posts by this user
Quote this message in a reply
01-06-2014, 11:19 AM
Post: #7
RE: HP Prime programmable eq solver
It was not the variables that was the problem, i did do a format and created the EQ... variables again, then there was no problem with MEM and LIST. There must have something else that was causing this problem.
Find all posts by this user
Quote this message in a reply
01-06-2014, 08:09 PM
Post: #8
RE: HP Prime programmable eq solver
Hello LarsF,
wow; it works pretty well now. I just modified a couple of things but it is definitely working well.

Here is the procedure for anyone who'd like to use it:

1) Create the following 3 variables:
EQLIB:={{"S=A*B", "S=A*B/2"},{"R=U/I","P=U*I"}}
EQLIBNAME:={{"Surface of a rectangle", "Surface of a triangle"},{"Ohms law","Effect"}}
EQTYPE:={"Area","Electric"}

2) Click on APPS, select the SOLVE, click on SAVE and name it EQLib

3) Edit the program EQLib (App) and copy the following code:

Code:

TYP:=1,EQ;
EXPORT EQLib()
BEGIN
END;

VIEW "Start",START()
BEGIN
  STARTVIEW(6,1);
  STARTVIEW(7,0);
END;

VIEW "Select type",STYPE()
BEGIN
  CHOOSE(TYP,"Select type",EQTYPE);
  STARTVIEW(7,0);
END;

VIEW "Solve EQ Lib",SOLVE()
BEGIN
  LOCAL I;
  CHOOSE(TYP,"Select type",EQTYPE);
  CHOOSE(EQ,"Solve EQ Lib",EQLIBNAME(TYP));
  E1:=EQLIB(TYP,EQ);
  FOR I := 0 TO 9 DO
    UNCHECK(I);
  END;
  CHECK(1);
  STARTVIEW(0,1);
  STARTVIEW(2,1);
END;

VIEW "Add Equation",ADD()
BEGIN
  LOCAL Equation:="", EQname:="";
  CHOOSE(TYP,"Select type",EQTYPE);
  IF INPUT({Equation,EQname},EQTYPE(TYP)+" Insert an EQ",{"EQ: ","EQ Name: "},{"Insert an EQ as string","Insert EQ name as string"}) THEN
    EQLIBNAME(TYP,0):=EQname;
    EQLIB(TYP,0):=Equation;
    STARTVIEW(7,0);
  END;
END;

Now you are ready to use it. Browse for the EQLib APP and launch it.

Enjoy

Giancarlo
Find all posts by this user
Quote this message in a reply
01-06-2014, 09:04 PM
Post: #9
RE: HP Prime programmable eq solver
Hi Giancarlo

I have made some small changes too, possibility to add EQ-type, some default values for EQ.. variables, so you just need to create them with EQTYPE:={} EQLIB:={} and EQLIBNAME:={}

I would be nice to be able to use some more descriptive names for variables in the formulas, but I don't know how to do that, maybe its not possible.

Code:

TYP:=1,EQ;
SET_DEFAULT();

EXPORT EQLib()
BEGIN
END;

VIEW "Start",START()
BEGIN
  IF SIZE(EQTYPE)==0 THEN
    //Init some default formula and names
    SET_DEFAULT(); 
  END;
  STARTVIEW(6,1);
  STARTVIEW(7,0);
END;

VIEW "Select EQ type",STYPE()
BEGIN
  CHOOSE(TYP,"Select EQ type",EQTYPE);
  STARTVIEW(7,0);
END;

VIEW "Solve EQ",SOLVE()
BEGIN
  LOCAL I;
  CHOOSE(EQ,"Solve "+EQTYPE(TYP)+" EQ",EQLIBNAME(TYP));
  E1:=EQLIB(TYP,EQ);
  FOR I := 0 TO 9 DO
    UNCHECK(I);
  END;
  CHECK(1);
  STARTVIEW(0,1);
  STARTVIEW(2,1);
END;

VIEW "Add new EQ type",ADD_TYPE()
BEGIN
  EDITLIST(EQTYPE); 
  STARTVIEW(7,0);
END;

VIEW "Add Equation",ADD()
BEGIN
  LOCAL Equation:="", EQname:="";
  IF INPUT({Equation,EQname},"Insert an "+EQTYPE(TYP)+" EQ",{"EQ: ","EQ Name: "},{"Insert an EQ as string","Insert EQ name as string"}) THEN
    EQLIBNAME(TYP,0):=EQname;
    EQLIB(TYP,0):=Equation;
  END;
  STARTVIEW(7,0);
END; 

SET_DEFAULT()
BEGIN
  EQTYPE:={"Area","Electric"};
  EQLIB:={{"S=A*B","S=A*B/2"},{"R=U/I","P=U*I"}};
  EQLIBNAME:={{"Area of an rectangle","Area of an triangle"},{"Ohms law","Effect"}}; 
END;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)