Post Reply 
Solver inside of HP basic
02-25-2015, 01:06 PM
Post: #1
Solver inside of HP basic
I wont to use the HP solver inside of the HP basic envoirment.
And think this should be the code.
But I dont know how to use the solve statement, the manual is'nt clear.

Export Kepler()
Begin
Local M=60,e=0.15,E;
HAngle:=0;
solve('E-sin(e)-M=0',E); < dont know how to do this???????
Print(E);
hAngle:=1;
End;

Thanks for any help.

Jan Kromhout
hellevoetsluis-NL
Find all posts by this user
Quote this message in a reply
02-25-2015, 01:41 PM (This post was last modified: 02-25-2015 01:53 PM by Angus.)
Post: #2
RE: Solver inside of HP basic
Hi,

Han has written a pretty good article about cas programming http://www.hpmuseum.org/forum/thread-3149.html. You might want to take a look at that.
I am sure e is a reserved name so you won't be able to use it and there are at least a lot of typos in your code.
Plus I am not sure if using capital Variables is advised. I never know if they will be treated symbolically or if their numerical value from home takes effect. For a local variable I think that should not happen, but I try to avoid single capital variables. I just can't get used to the home/cas thingy in the calculator.

To make it short: a cas function would do it nicely and very straightforward:
#cas
kepler(mass):=
BEGIN
local vale:=0.15;

ret_val:= solve(valE-sin(vale)-mass=0,valE);
return ret_val;
END;
#end

I left out angle. I don't know what it does.
Find all posts by this user
Quote this message in a reply
02-25-2015, 02:04 PM
Post: #3
RE: Solver inside of HP basic
Since this is just a plain numeric solving, just use the numeric solver command. FNROOT is what you are looking for. No other changes are needed in your first posted program.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
02-26-2015, 09:17 AM (This post was last modified: 02-26-2015 09:18 AM by Thomas Ritschel.)
Post: #4
RE: Solver inside of HP basic
(02-25-2015 02:04 PM)Tim Wessman Wrote:  Since this is just a plain numeric solving, just use the numeric solver command. FNROOT is what you are looking for. No other changes are needed in your first posted program.

By changing Jan's code into the following I get "Kepler Error: Bad Guess(es)":
Code:
EXPORT Kepler()
BEGIN
  LOCAL M=60, e=0.15, E;
  HAngle:=0;
  FNROOT(E-SIN(e)-M,E);
  PRINT(E);
  HAngle:=1;
END;

I also tried other variants, e.g. FNROOT('E-SIN(e)-M=0',E) or by providing some proper guess, but it keeps showing the error message. The problem may be caused by the use of local variables: By using the single letter HOME variables, e.g. by removing the LOCAL statement (and changing "e" into some other capital letter), the error message disappears. But then it's just printing "0" instead of the correct result...

BTW.: I'm using the latest (?) calculator software version 6975.
Find all posts by this user
Quote this message in a reply
02-26-2015, 02:59 PM
Post: #5
RE: Solver inside of HP basic
(02-26-2015 09:17 AM)Thomas Ritschel Wrote:  
(02-25-2015 02:04 PM)Tim Wessman Wrote:  Since this is just a plain numeric solving, just use the numeric solver command. FNROOT is what you are looking for. No other changes are needed in your first posted program.

By changing Jan's code into the following I get "Kepler Error: Bad Guess(es)":
Code:
EXPORT Kepler()
BEGIN
  LOCAL M=60, e=0.15, E;
  HAngle:=0;
  FNROOT(E-SIN(e)-M,E);
  PRINT(E);
  HAngle:=1;
END;

I also tried other variants, e.g. FNROOT('E-SIN(e)-M=0',E) or by providing some proper guess, but it keeps showing the error message. The problem may be caused by the use of local variables: By using the single letter HOME variables, e.g. by removing the LOCAL statement (and changing "e" into some other capital letter), the error message disappears. But then it's just printing "0" instead of the correct result...

BTW.: I'm using the latest (?) calculator software version 6975.

I have modified the code a little bit, because it shoeld solved in radians.
Still I get the same massage.
After change this code
EXPORT Kepler()
LOCAL M=60*pi/180,e=0.15,X;
X:=FNROOT(E-e*sin(E)-M,E);
PRINT(X*180/pi);
END;

And change the line of FNROOT into

X:=FNROOT(E-0.15*sin(E)-60*pi/180,E);

than it working, this tells me that FNROOT is not able to use variable.
Strange behavior.
Find all posts by this user
Quote this message in a reply
02-26-2015, 03:33 PM (This post was last modified: 02-26-2015 04:26 PM by Thomas Ritschel.)
Post: #6
RE: Solver inside of HP basic
I've got it working using the following code without the use of local variables:
Code:
EXPORT Kepler()
BEGIN
  M:=60*pi/180;   <-- use the "pi" key (shift + 3)
  A:=0.15;
  HAngle:=0;
  PRINT(FNROOT(E-A*SIN(E)-M,E));
  HAngle:=1;
END;

Obviously the solution isn't stored in the variable E. Therefore one needs to get the return value of FNROOT instead. This wasn't clear to me...

Anyway, I'm still wondering why one cannot use local variables here.

Edit: Equation corrected...
Find all posts by this user
Quote this message in a reply
02-26-2015, 04:20 PM
Post: #7
RE: Solver inside of HP basic
Turns out that local variables aren't fully carried through with with the solver call which I did not know. The primary reason is that you could run into a situation where you are doing something like LOCAL A; FNROOT(F1(X)-A,X) where F1 is defined as A+5. The question then arises: which value of A is being referred to here? The global A or the local A.

A similar issue could arise on the 50g for example when you try to solve a formula defined in directories up from your current and no defines in those location. It could result in all sorts of unexpected behavior.

I've put this on the list of things to look at and see what we might be able to do.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
03-06-2015, 04:18 PM
Post: #8
RE: Solver inside of HP basic
Thanks for any help so far. The solver is working great.
Now I understand how it works.
One question is still open for me. What is the accuracy of the the solver?
Is it posible to set this accuracy with a variable?
As an example, suggest this variable is eps.
And now when I set this to eps=0.001 the solver is find fast the condition to stop solving and give back the answer.



Jan Kromhout
Hellevoetsluis-NL
Find all posts by this user
Quote this message in a reply
Post Reply 




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